Access - making selection from a ComboBox mandatory

Posted on 2009-05-20
Medium Priority
Last Modified: 2012-06-27

I have a ComboBox on an Access form and I want the user to be forced to select something from the dropdown. How do I do this?
Question by:Murray Brown
  • 4
  • 2
LVL 75
ID: 24434394
You can do this:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Nz(Me.YourComboBoxName,"")="" Then
   msgbox "You must enter a value"
   Cancel = True
End If

End Sub

LVL 75

Accepted Solution

DatabaseMX (Joe Anderson - Microsoft Access MVP) earned 2000 total points
ID: 24434404
This way ... if the user tries to save a record w/o a value in the combo, the BU event will catch this.


Author Closing Comment

by:Murray Brown
ID: 31583621
Thanks very much
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

LVL 75
ID: 24434711
You are welcome.


Expert Comment

ID: 24434763
A better option is using the list index because if it is a bound field then it will sometimes show blank but it will contain value making it where the null trap doesn't work. By using listindex = -1 it means that there is nothing selected and then you send an alert and reset the focus back to the combobox.

If Me.cboName.ListIndex = -1 Then
  MsgBox "A value is required for ...."
  Cancel = True
End If
LVL 75
ID: 24434829
"null trap doesn't work"

Actually, it does ... only it would be (for a single select list box):

If IsNull(Me.YourListBoxName) = True Then
  ' ...

And lets just say the List box is a 'different' option.


Author Comment

by:Murray Brown
ID: 24434937
Hi mcfitz13 - I actually should have allocated some points to you..sorry

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
When we develop an application in Ms Access 2016 we should also try to protect the queries, macros and table links. I know I may not have a permanent solution but for novice users, they will not manage to break your application. Below is the detail …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question