Checking for a blank value in a combo box

  • Thread starter Thread starter David P.
  • Start date Start date
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????
 
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...................
 
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.
 
i hope it'd be ok to join this thread.

in my code below, i am trying to determing if 'DateDth' occurs before
'LTFUDate' and to issue a message at that point, yet A2K is giving me one of
these '424' errors.

can you spot the 'achilees heel' in my code below:

Option Compare Database

Private Sub Form_Current()

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


If Me.LTFUDate Is Not Null And Me.DateDth Is Not Null Then

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

End If
End Sub
 
as John said in the previous post, you have to use the IsNull() function, as

If Not IsNull(Me.LTFUDate) And Not IsNull(Me.DateDth) Then

hth
 
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
 
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! :)
 
Back
Top