Solved

Access - making selection from a ComboBox mandatory

Posted on 2009-05-20
7
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 - Microsoft MVP, Access and Data Platform) 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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