popup message if combo left empty

cdoyle

Registered User.
Local time
Today, 13:59
Joined
Jun 9, 2004
Messages
383
Hi,
Having a odd problem but I'm sure I'm just overlooking something.

I have a combo box, that I need the users to select one of the items. If they leave it blank I want a message to appear telling them what to do.

I was using this code
Private Sub Form_BeforeUpdate(Cancel As Integer)
If (IsNull([Combo2])) Then
MsgBox "Please Select a Edit Type", vbOKOnly, "Edit Type"
Exit Sub
End If
End Sub

and that works, but only if the bound field is a text field. But my combo is bound to a number field, and it doesn't work. It doesn't give me any message at all.

What am I missing?
 
Try:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If [COLOR="Red"]Len(Me.Combo2 & "") = 0[/COLOR] Then
   MsgBox "Please Select a Edit Type", vbOKOnly, "Edit Type"
   [COLOR="Red"]Cancel = True[/COLOR]
End If
End Sub
 
That didn't seem to work either.

It lets me go right to the next record without any message
 
Do you have a default value for the bound field in the table? Zero maybe? How about:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Combo2 = 0 Then
   MsgBox "Please Select an Edit Type", vbOKOnly, "Edit Type"
   Cancel = True
End If
End Sub
 
Do you have a default value for the bound field in the table? Zero maybe? How about:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Combo2 = 0 Then
   MsgBox "Please Select an Edit Type", vbOKOnly, "Edit Type"
   Cancel = True
End If
End Sub

that was it!
I never noticed that Access automatically fills in that field when you make it a number field.

Thanks!
 

Users who are viewing this thread

Back
Top Bottom