Validate Form Field

S

Stephen Lynch

I am trying to validate a form field. I do not want to validate at table
level for special reasons.

When I put this code on a button, I get the message "Not Null" even though
the address field is empty.

If Forms![EmployeeDetail]![Address1] = "" Then
MsgBox "Please enter an Address for this Participant"
Else
MsgBox "Not Null"
End If

Anybody know why? I tried .Value = Null, but it errors out.

TIA

Steve
 
D

Douglas J Steele

Try:

If Len(Forms![EmployeeDetail]![Address1] & "") = 0 Then

That will check for both Null or zero-length strings ("")
 
R

Rick Brandt

Stephen said:
I am trying to validate a form field. I do not want to validate at
table level for special reasons.

When I put this code on a button, I get the message "Not Null" even
though the address field is empty.

If Forms![EmployeeDetail]![Address1] = "" Then
MsgBox "Please enter an Address for this Participant"
Else
MsgBox "Not Null"
End If

Anybody know why? I tried .Value = Null, but it errors out.

TIA

Steve

= "" will not be satisifed if the field is Null as Null is not the same as "".
In addition you can't test for Null with "=". You have to use the IsNull()
function. If the field allows zero length strings ("") then the best thing to
do is cover both possibilities. I usually use...

If Len(Nz(Forms![EmployeeDetail]![Address1],"")) = 0 Then...
 
S

Stephen Lynch

Thanks Guys


Rick Brandt said:
Stephen said:
I am trying to validate a form field. I do not want to validate at
table level for special reasons.

When I put this code on a button, I get the message "Not Null" even
though the address field is empty.

If Forms![EmployeeDetail]![Address1] = "" Then
MsgBox "Please enter an Address for this Participant"
Else
MsgBox "Not Null"
End If

Anybody know why? I tried .Value = Null, but it errors out.

TIA

Steve

= "" will not be satisifed if the field is Null as Null is not the same as
"". In addition you can't test for Null with "=". You have to use the
IsNull() function. If the field allows zero length strings ("") then the
best thing to do is cover both possibilities. I usually use...

If Len(Nz(Forms![EmployeeDetail]![Address1],"")) = 0 Then...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top