Clear Combo Box selection

  • Thread starter Thread starter Christine
  • Start date Start date
C

Christine

A have two combo boxes on a form that the user can use to
select search criteria for a subform based on (mutually-
exclusive) option buttons.

Each time the user moves between the two boxes, I'd like
their previous selection in the combo to disappear. I
have tried a suggestion by ??? that I found in the posts,
but it doesn't work for me:

'A1 - assign a value that is listed in the bound column of
'> the combobox. For example bound Column(0) employeeID =
'> 1023 and visible Column(1) Employee = "Eric Idle"
'>
'> cboEmployeeID.value=1023 will select Eric Idle
'>
'> A2 - with cboEmployeeID
'> .value=.itemdata(-1)
'> End With

Here is the above code (in Select Case 2) in my
application:

Private Sub FrameSearchChoice_AfterUpdate()
' Set main form controls & link criteria for the subform

Select Case Me.FrameSearchChoice
Case 1 'Search by CARNum
Me.CARNum.Enabled = True
Me.AssignToID.Enabled = False
Me.subfrm_Respond_Dialog.LinkMasterFields = "CARNum"
Me.subfrm_Respond_Dialog.LinkChildFields = "CARNum"
Case 2 'Search by AssignToID
Me.AssignToID.Enabled = True
AssignToID.Value = 1

With AssignToID
.Value = .ItemData(-1)
End With

Me.CARNum.Enabled = False
Me.subfrm_Respond_Dialog.LinkMasterFields =
"AssignToID"
Me.subfrm_Respond_Dialog. _
LinkChildFields = "AssignToID"
End Select
End Sub

The With...Endwith doesn't do anything. I have tried it
in various places/events with no success. If it matters,
the combo boxes are unbound.

Any help with ???'s code or another suggestion to clear
combo boxes will be apppreciated!
As always, thanks to all,
Christine
 
Christine said:
A have two combo boxes on a form that the user can use to
select search criteria for a subform based on (mutually-
exclusive) option buttons.

Each time the user moves between the two boxes, I'd like
their previous selection in the combo to disappear. I
have tried a suggestion by ??? that I found in the posts,
but it doesn't work for me:

'A1 - assign a value that is listed in the bound column of
'> the combobox. For example bound Column(0) employeeID =
'> 1023 and visible Column(1) Employee = "Eric Idle"
'>
'> cboEmployeeID.value=1023 will select Eric Idle
'>
'> A2 - with cboEmployeeID
'> .value=.itemdata(-1)
'> End With

Here is the above code (in Select Case 2) in my
application:

Private Sub FrameSearchChoice_AfterUpdate()
' Set main form controls & link criteria for the subform

Select Case Me.FrameSearchChoice
Case 1 'Search by CARNum
Me.CARNum.Enabled = True
Me.AssignToID.Enabled = False
Me.subfrm_Respond_Dialog.LinkMasterFields = "CARNum"
Me.subfrm_Respond_Dialog.LinkChildFields = "CARNum"
Case 2 'Search by AssignToID
Me.AssignToID.Enabled = True
AssignToID.Value = 1

With AssignToID
.Value = .ItemData(-1)
End With

Me.CARNum.Enabled = False
Me.subfrm_Respond_Dialog.LinkMasterFields =
"AssignToID"
Me.subfrm_Respond_Dialog. _
LinkChildFields = "AssignToID"
End Select
End Sub

The With...Endwith doesn't do anything. I have tried it
in various places/events with no success. If it matters,
the combo boxes are unbound.

Any help with ???'s code or another suggestion to clear
combo boxes will be apppreciated!
As always, thanks to all,
Christine

I don't know what a reference to .ItemData(-1) is supposed to
accomplish, since AFAIK the .ItemData collection begins with item 0, and
..ItemData(-1) would not be a valid reference. Anyway, it seems to me
that all you need to do to clear the value in a particular combo box is
to set its value to Null:

Me.AssignToID = Null

I notice that your code first has this line:
AssignToID.Value = 1

I don't see the point of that, if your intention is to clear the combo
box.
 
Back
Top