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
...
 

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