Checking for a blank value in a combo box

D

David P.

I have a form with a combo box and a button on it. When
the user pushes the button I want a new form to open with
the record that is selected in the combo box. I have that
working fine. If the combo box is blank the new form
opens on a blank record, I would like a message box to pop
up if there is no record in the combo box. Here is what I
have coded but it is not working, I am getting a run-time
error '424': Object Required. Here is teh code I am
using...

Me.cboMachineNumber.SetFocus
If Me.cboMachineNumber.Value Is Not Null Then
DoCmd.RunMacro "mcro_OpenMachineHyperlinks"
Else
MsgBox "You must select a Machine Number"
End If

I also tried this code...

Me.cboMachineNumber.SetFocus
If me.cboMachineNumber.Value = "" then
MsgBox "You must select a Machine Number"
Else
DoCmd.RunMacro "mcro_OpenMachineHyperlinks"
End If

Anyone know what I am doing wrong????
 
B

Bill

David P. said:
I have a form with a combo box and a button on it. When
the user pushes the button I want a new form to open with
the record that is selected in the combo box. I have that
working fine. If the combo box is blank the new form
opens on a blank record, I would like a message box to pop
up if there is no record in the combo box. Here is what I
have coded but it is not working, I am getting a run-time
error '424': Object Required. Here is teh code I am
using...

Me.cboMachineNumber.SetFocus
Correct syntax for checking for a null value in a control...................
 
J

John Spencer (MVP)

Try one of the following

If IsNull(Me.cboMachineNumber.Value) = True Then ...

If Len(Trim(Me.cboMachineNumber.Value & vbNullstring)) = 0 Then ...

In VBA you must use the IsNull function to determine if something is null.
 
T

Ted

how 'bout this one, tina?


Private Sub Form_Current()

Dim LTFUDate As Date, DateDth As Date, Message As String, Days As Integer


If IsNull(Me.LTFUDate And Me.DateDth) = False Then

If DateDiff("d", Me.LTFUDate, Me.DateDth) < 0 Then
Message = MsgBox("Date of Death Should Coincide/Follow LTFU Date",
vbCritical)
End If

End If
End Sub
 
T

tina

i don't know - i've never used multiple field references in the IsNull()
function. i'd say, test it to see if it returns the correct values. or wait
to see if somebody with a definite answer posts. or both. good luck! :)
 

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