Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox Validation?

Status
Not open for further replies.

Tezdread

Technical User
Oct 23, 2000
468
GB
Hi,

I have set my combobox to 'Limit To List' and have tried various Input Mask options but I haven't found out how I can stop people going to a new record if all the combobox fields haven't been selected...

Basically my form has a few comboboxes and each one of these needs to be selected, they can't be blank and can only contain the text that is already in the combobox.

Can anyone advise?

Tezdread
"With every solution comes a new problem"
 
Try this
Code:
Private Sub cmdNew_Click()
Me.Combo0.SetFocus
If Me.Combo0.Text = "" Then
MsgBox "Select Combo0 text"
Exit Sub
Else
Me.Combo2.SetFocus
If Me.Combo2.Text = "" Then
MsgBox "Select Combo2 text"
Exit Sub
Else
MsgBox "new record" 'here you put the code to go to new
End If
End If
End Sub
regards

Zameer Abdulla
 
nice one Zmr but I'm not familiar with the coding aspect...could you advise on where this needs to go and how I get it there?

I tried [even procedure] on the On Change option but this didn't work?

Tezdread
"With every solution comes a new problem"
 
You said users are moving to the new record without filling all the combo boxes.
So we need to add some code on the click button to move to new record.
first of all you have to remove Navigation buttons from the form to make sure that user is moving to the new record through the way you direct.
So to go to the new record you have a command button called "cmdAdd"

on click the cmdAdd use this code. Remember to change the combo names to appropriate combo names
Code:
Private Sub cmdAdd_Click()
Me.Combo0.SetFocus
If Me.Combo0.Text = "" Then 'Check the first combo has text
MsgBox "Select Combo0 text"
Exit Sub
Else                'If the first is ok then test second
Me.Combo2.SetFocus
If Me.Combo2.Text = "" Then
MsgBox "Select Combo2 text"
Exit Sub
                'do the same to all of them.
Else 'If all are filled with text then allow user to move
     'new record
 DoCmd.GoToRecord , , acNewRec
End If
End If
End Sub

Also add the following code to each one of the comboboxes to confirm that user is selecting only those items already in the list. Remember to change the YourComboName to actual name of the combo
Code:
Private Sub YourComboName_Exit(Cancel As Integer)
If Me.YourComboName.Text <> Me.YourComboName.ListIndex Then
         'If the item not from the list
MsgBox "select item form list"
Me.YourComboName.SetFocus
Me.YourComboName.Text = ""
End If
End Sub

Zameer Abdulla
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top