This only makes sense if your combobox is bound to a field in the underlying
table. You can check this, in Design View, if you're uncertain, by selecting
the combobox, then going to Properties - Data and seeing if there's a field
name listed in the Control Source Property.
If the combobox is, indeed, bound, then Fred's code will do the trick. You
should, however, probably place it in the form's BeforeUpdate event. This way,
it will also warn the user if they simply try to move to another record or
enter another new record, as well as if they try to close the form, with the
field in question empty.
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([ControlName]) Then
MsgBox "You must enter data."
Cancel = True
Me![ControlName].SetFocus
End If
End Sub
Copy the code
From Design View, hit >Control> + <G> to go to the code window
Directly below the line
Option Compare Database
paste the code. Now simply replace ***ControlName*** in the code with the
actual name of your combobox. You should now be set.
Simply replace ControlName with the actual name of your combobox.