validating a null field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am validating some field entries through VBA code. I have to do it in code because I'm checking a number of entries.
My problem is that the field in question contains a blank. The first time I come through my process it sees the null field and gives the required message. If I then cancel out and come back into the record, the next time it does not see the field as blank and thus does not give the message. (Even if I close the database completely it is never seen as blank again) Why is it not seeing my field as blank when it is? I have tried storing myCustomer = "" and also doing nothing. The code is:
If IsNUll(me![mycustomer]) then
strMyMessage = "You must enter a customer!"
End If
I then do some other things and then go show the message.

Thanks for any help you can give! It's driving me nuts!
 
Try this way of testing for a Null or an empty string (is that what you mean
by "blank"?):

If Len(Me!MyCustomer & "") = 0 Then
strMyMessage = "You must enter a customer!"
End If

--
Ken Snell
<MS ACCESS MVP>

macy said:
I am validating some field entries through VBA code. I have to do it in
code because I'm checking a number of entries.
My problem is that the field in question contains a blank. The first time
I come through my process it sees the null field and gives the required
message. If I then cancel out and come back into the record, the next time
it does not see the field as blank and thus does not give the message. (Even
if I close the database completely it is never seen as blank again) Why is
it not seeing my field as blank when it is? I have tried storing myCustomer
= "" and also doing nothing. The code is:
If IsNUll(me![mycustomer]) then
strMyMessage = "You must enter a customer!"
End If
I then do some other things and then go show the message.

Thanks for any help you can give! It's driving me nuts!
 
The primary key of your customer table ought to be MyCustomerID (autonumber).
Then check if MyCustomerID is null and it should work every time!


--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com



macy said:
I am validating some field entries through VBA code. I have to do it in code
because I'm checking a number of entries.
My problem is that the field in question contains a blank. The first time I
come through my process it sees the null field and gives the required message.
If I then cancel out and come back into the record, the next time it does not
see the field as blank and thus does not give the message. (Even if I close the
database completely it is never seen as blank again) Why is it not seeing my
field as blank when it is? I have tried storing myCustomer = "" and also doing
nothing. The code is:
If IsNUll(me![mycustomer]) then
strMyMessage = "You must enter a customer!"
End If
I then do some other things and then go show the message.

Thanks for any help you can give! It's driving me nuts!
 
Back
Top