VBA code problem

E

Ernie Lippert

If [FunctionHours] = Null Then
[DateCompleted].SetFocus

If [DateCompleted].Value > 0 Then
Response = MsgBox("When a completed project date is entered,
Total Function Hours must be entered. 0 is allowed. ", vbOKOnly, "Completed
Project Warning")
DoCmd.GoToControl "FunctionHours"
Else
End If

End If

What is wrong with this code. When [FunctionCode] = Null the code goes to
the final End If without executing the in interveining code. Must be
something faily stupid.
 
S

Stuart McCall

Ernie Lippert said:
If [FunctionHours] = Null Then
[DateCompleted].SetFocus

If [DateCompleted].Value > 0 Then
Response = MsgBox("When a completed project date is
entered,
Total Function Hours must be entered. 0 is allowed. ", vbOKOnly,
"Completed
Project Warning")
DoCmd.GoToControl "FunctionHours"
Else
End If

End If

What is wrong with this code. When [FunctionCode] = Null the code goes to
the final End If without executing the in interveining code. Must be
something faily stupid.

Nothing can be equal to null. In SQL, values can be compared to null using:

ValueName Is Null

but in VBA you must use the IsNull function:

If IsNull(ValueName) Then
 
B

Beetle

Maybe it's not Null, maybe it's a zero length string. You might
try;

If Nz([FunctionHours], "") = "" Then
...
 
Top