Solved

Access - making selection from a ComboBox mandatory

Posted on 2009-05-20
7
251 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 - 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

828 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