Test for a Combo Box empty or not...

  • Thread starter Thread starter James
  • Start date Start date
J

James

From a report print command button on a form, I am trying to check to see
that a combo box selection was made before continuing.

My code:

If Me![Employee ID] = "" Then
MsgBox "Please select a Representative!", , "Missed Field Alert"
Me![Employee ID].SetFocus
End If

The problem is my code doesn't detect the empty combo box.

Any suggestions appreciated.
 
From a report print command button on a form, I am trying to check to see
that a combo box selection was made before continuing.

My code:

If Me![Employee ID] = "" Then
MsgBox "Please select a Representative!", , "Missed Field Alert"
Me![Employee ID].SetFocus
End If

The problem is my code doesn't detect the empty combo box.

Any suggestions appreciated.

Try:
If IsNull(Me![EmployeeID]) then
 
James said:
From a report print command button on a form, I am trying to check to see
that a combo box selection was made before continuing.

My code:

If Me![Employee ID] = "" Then
MsgBox "Please select a Representative!", , "Missed Field Alert"
Me![Employee ID].SetFocus
End If

The problem is my code doesn't detect the empty combo box.

Any suggestions appreciated.

Resolved using:

If IsNull(Me![Employee ID]) Then
 
I believe that under certain circumstances a combo can have a zero length
string value so it's better to test for Null and "" (zero length string).
The following does both:

If Len(Me![Employee ID] & "") = 0 Then
....

Jon
 
mie via AccessMonster.com said:
to add some fun, this is more efficient..

Me![Employee ID].ListIndex = -1


That tells you whether the value of the combo box is in its list, but it
doesn't guarantee that the user hasn't entered anything at all, unless the
combo also has its Limit To List property set to Yes/True.
 
Back
Top