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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making Combo box in form required

Status
Not open for further replies.

thrilliam

Technical User
Oct 11, 2006
12
US
I have two tables and one form

My form has a combobox "customer name" which pulls its info from table 2 named "customers" when selecting the customer name in the combo it updates the field customer in table one. How can I make my " customer name" combo box a required field before closing the form r moving on to the next record?

Thanks
 
A common way is to enforce all the validation rules in the BeforeUpdate event procedure of the form, playing with the SetFocus method and the Cancel argument.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Could you provide a little more info on the SetFocus method? My knowledge of VBA is minimal at best.
 
How are ya thrilliam . . .

In the [blue]BeforeUpdate[/blue] event of the form, something like this:
Code:
[blue]   Dim CBx As ComboBox, Msg As String, Style As Integer, Title As String
   
   Set CBx = Me![purple][b][i]YourComboboxName[/i][/b][/purple]
   
   If CBx.ListIndex = -1 Then
      Msg = "Data is required in combobox!"
      Style = vbCritical + vbOKOnly
      Title = "Required Data Error! . . ."
      MsgBox Msg, Style, Title
      
      CBx.SetFocus
      Cancel=True
   End If

   Set CBx=Nothing[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks Aceman,
So I tested out your code and it only seems to work if I make a selection in my combo box and then delete it. After deleting my selection if i try to move one or close the window it gives me the error. If i never make a selection and the combo box remains blank i can still move on.

With the code I also get a run time error after the message box pops up. The error is at CBx.SetFocus
the message says "You must save the field before you execute the GoToControl method, or the SetFocus method."


Thanks,
Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top