Solved

Access - making selection from a ComboBox mandatory

Posted on 2009-05-20
7
220 Views
Last Modified: 2012-06-27
Hi

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?
0
Comment
Question by:murbro
  • 4
  • 2
7 Comments
 
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

mx
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 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.

mx
0
 

Author Closing Comment

by:murbro
ID: 31583621
Thanks very much
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 75
ID: 24434711
You are welcome.

mx
0
 
LVL 1

Expert Comment

by:mcfitz13
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 ...."
  Me.cboName.SetFocus
  Cancel = True
End If
0
 
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.

mx
0
 

Author Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now