• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Access - making selection from a ComboBox mandatory

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
Murray Brown
Asked:
Murray Brown
  • 4
  • 2
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
You are welcome.

mx
0
 
mcfitz13Commented:
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
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi mcfitz13 - I actually should have allocated some points to you..sorry
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now