1
votes

In Access 2010, I am struggling with making a combobox force users to give it input on a data entry form. In this case, I want the combobox to detect that the user has made no selection at all.

I've put the included code in the OnClick, BeforeUpdate, and OnChange events of cbo_Event1. cmb_StartOfSeason, cmb_EndOfSeason, and cmb_MoneyRequired are comboboxes which will provide details for the user about cbo_Event1 on the search form. All four comboboxes are linked to other tables for lookup values.

I've made bound (cbo_Event1) and unbound (cmb_Event) versions of the combobox. I've also used Me.cbo_Event1.Value, Me.cbo_Event1.ListIndex, and Me.cbo_Event1 in the code.

Private Sub cbo_Event1_AfterUpdate()
   MsgBox ("Me.cbo_Event1 = " & Me.cbo_Event1 & ".")
   If Me.cmb_Event = 0 Then
      Me.cmb_StartOfSeason = 0
      Me.cmb_EndOfSeason = 0
      Me.cmb_MoneyRequired = 0
   End If
End Sub

Private Sub cbo_Event1_Change()
   MsgBox ("Me.cbo_Event1 = " & Me.cbo_Event1 & ".")
   If Me.cmb_Event = 0 Then
      Me.cmb_StartOfSeason = 0
      Me.cmb_EndOfSeason = 0
      Me.cmb_MoneyRequired = 0
   End If
End Sub

Private Sub cbo_Event1_Click()
   MsgBox ("Me.cbo_Event1 = " & Me.cbo_Event1 & ".")
   If Me.cmb_Event = 0 Then
      Me.cmb_StartOfSeason = 0
      Me.cmb_EndOfSeason = 0
      Me.cmb_MoneyRequired = 0
   End If
End Sub

Private Sub cmb_Event_AfterUpdate()
   MsgBox ("Me.cmb_Event = " & Me.cmb_Event & ".")
   If Me.cmb_Event = 0 Then
      Me.cmb_StartOfSeason = 0
      Me.cmb_EndOfSeason = 0
      Me.cmb_MoneyRequired = 0
   End If
End Sub

Private Sub cmb_Event_BeforeUpdate(Cancel As Integer)
   MsgBox ("Me.cmb_Event = " & Me.cmb_Event & ".")
   If Me.cmb_Event = 0 Then
      Me.cmb_StartOfSeason = 0
      Me.cmb_EndOfSeason = 0
      Me.cmb_MoneyRequired = 0
   End If
End Sub

Private Sub cmb_Event_Change()
   MsgBox ("Me.cmb_Event = " & Me.cmb_Event & ".")
   If Me.cmb_Event = 0 Then
      Me.cmb_StartOfSeason = 0
      Me.cmb_EndOfSeason = 0
      Me.cmb_MoneyRequired = 0
   End If
End Sub

Private Sub cmb_Event_Click()
   MsgBox ("Me.cmb_Event = " & Me.cmb_Event & ".")
   If Me.cmb_Event = 0 Then
      Me.cmb_StartOfSeason = 0
      Me.cmb_EndOfSeason = 0
      Me.cmb_MoneyRequired = 0
   End If
End Sub

I get the same result across the board: the Event combobox does not detect that no selection was made when its drop-down list appears. The MsgBox function doesn't even trigger, indicating the event doesn't take place. I'm baffled as to why.

2
Well, are you trying to account for blank selections? Try using LEN(Me.cmb_Event.Vaue)>0. I would also make sure the control name is correct. - Doug Coats
I'll have to try blank selections when I get home tonight. I know I've struggled to make those work, too. From what I've experienced, Access VBA is pretty complicated when it comes to handling nulls, null strings, zeroes, and blanks. - N.Barrett
Show us the properties tab labeled "Other" for this control - Doug Coats
Here are the requested screenshots. !Valid XHTML !Valid XHTML - N.Barrett
I didn't get much time to test for blank selections. Even those are a mystery to me, and it was a struggle to post those screenshots. - N.Barrett

2 Answers

1
votes

The only time I ever seen event handlers not firing like this is when writing (or pasting) an event handler doesn't actually link it to the appropriate event property and it is not listed in the event property sheet.

If you create the Sub statement by selecting the handler from the drop-down it will add it to the property sheet, or it can be added manually.

I presume you've also tried setting a breakpoint on the first statement of the handlers. If it doesn't hit it, then the handler is not linked to the control.

0
votes

I think your issues has to do with testing the wrong values. Unless you are setting the default values to 0 (this is assuming there are no bound tables) then the controls will most likely never have 0 in them. And, if youre trying to test for nulls there are much better ways to do so

LEN(TRIM(Me.cmb_Event.Vaue))>0

or

 ISNULL(Me.cmb_Event.Vaue)=True 

I had no issue replicating your scenario:

enter image description here