making combo box mandatory

jlocke

Registered User.
Local time
Today, 02:14
Joined
Jul 23, 2002
Messages
31
I'm looking to make a combo box mandatory. Users have been leaving it blank. Would also be nice if the code could check to see if the box matches what the combo list as available.

Thank you

still learning...
 
Well.....

First off all you have to do is set limit to list to Yes.
Second depends on weather or not you are using VBA or the garbage wizard recordset.... I personally add all my own records, because I am a control freak and hate the wizards....
If you are using VBA which I recommend you to to take the time to learn if you aren't using it. You the check to see if the ISNULL(cmbxxx.value) = true, if so you do not add the record and you msgbox"All fields required have not been entered",vbOKOnly,"Record Error"
At this time you can turn the background color of the missing field to red, so the user knows what they need to enter...
If you are using the wizard, in the table, for the field being populated by the "cmbxxx" you just make the field required, and there will be an error when the user tried to add this record...

Regards,
 
To limit the combo box to the list…

Set “Limit to List” to yes on the data tab in the properties of your combo box… This will only allow a selection from the items in the list.

Then on the event tab on the properties of the combo box add the following Event Procedure to “On Not in List”;

Private Sub Title_NotInList(NewData As String, Response As Integer)
MsgBox "Put the message you want your users to see here"
Response = acDataErrContinue
End Sub


To prevent users from leaving without entering something in the combo box add the following code to the BeforeUpdate event in the properties of the form;

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.YOURCOMBOBOXNAME) Then
MsgBox "The blank field is required....", vbOKOnly
Me.COMBOBOXNAME.SetFocus
Cancel = True
Exit Sub
End If
End Sub


Hope this helps...

Don

*** Edited because the above post wasn't here when I started my reply :D
 
thank you al for your help works great!

donbettis said:
To limit the combo box to the list…

Set “Limit to List” to yes on the data tab in the properties of your combo box… This will only allow a selection from the items in the list.

Then on the event tab on the properties of the combo box add the following Event Procedure to “On Not in List”;

Private Sub Title_NotInList(NewData As String, Response As Integer)
MsgBox "Put the message you want your users to see here"
Response = acDataErrContinue
End Sub


To prevent users from leaving without entering something in the combo box add the following code to the BeforeUpdate event in the properties of the form;

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.YOURCOMBOBOXNAME) Then
MsgBox "The blank field is required....", vbOKOnly
Me.COMBOBOXNAME.SetFocus
Cancel = True
Exit Sub
End If
End Sub


Hope this helps...

Don

*** Edited because the above post wasn't here when I started my reply :D
 
Only problem....

If the user never clicks or tabs onto the combo box then they can add the record with a null value.....

Regards....
 
The BeforeUpdate Event is place on the properties of the form...Not the field...

When leaving the form...If the field has a null value it will pop up the message box...Once the OK button it clicked it will then setfocus back to the combo box field...

Don
 
Last edited:
Question...?

What happens when they change other values, on other controls, will this not send the user right to the cmbXXX since the control is still null...?

Regards,
 
The BeforeUpdate Event will only come into play when a user attempts to exit (close, move on to the next record, etc...) the form... If the combo has a valid value; the event will go un-noticed and, the form will close; if the combo box has a null value it will trigger the event and, it will pop up the message box.

Don
 

Users who are viewing this thread

Back
Top Bottom