Test for a Combo Box empty or not...

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

fredg

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
 
J

James

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
 
J

Jon Lewis

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
 
M

mie via AccessMonster.com

to add some fun, this is more efficient..

Me![Employee ID].ListIndex = -1

..and actually, you dont have to test for null value like

If IsNull(Me![Employee ID]) then
'--do something
end if

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

Dirk Goldgar

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.
 

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