[AccessD] Unable to deselect items in unbound combobox

Bill Benson bensonforums at gmail.com
Wed Dec 31 11:16:43 CST 2014


Looking up online how to reset a combo, this code appears now in substitute,
however it still is a question in my mind why setting Selected to false
fails to work for unselecting a combo item?

 

Private Sub ClearField(ctrl As Control)

Dim i As Long

Select Case TypeName(ctrl)

 

Case Is = "Listbox"

    ctrl = ""

Case Is = "ComboBox"

    ctrl = ""

Case Is = "TextBox"

    ctrl = ""

Case Is = "CheckBox"

    ctrl = False

Case Else

    MsgBox "Fix code!"

End Select

 

End Sub

 

From: Bill Benson [mailto:bensonforums at gmail.com] 
Sent: Wednesday, December 31, 2014 12:11 PM
To: 'Access Developers discussion and problem solving'
Subject: Unable to deselect items in unbound combobox

 

I have a listbox that when it is requeried, I desire to deselect any of its
contents, and then, since it's column 0 value represents the intended
product id, on which the form itself is positioned, I want there to be no
current record of the form (until such time as the user makes a selection in
the listbox), as well as a bunch of other unbound controls to be set to null
or the equivalent. Many of those controls are unbound comboboxes, and here
comes my problem. I pass the controls to this function and while I am not
getting any errors and the selected property of each item in the combo is
apparently both false at the time the routine happens to be called (in this
instance), 

 

1)      The listindex appears nevertheless to be other than -1, and

2)      The listindex does not change. 

 

The result of this is that I am not seemingly able to de-select any value
already showing in those combos.

 

Private Sub ClearField(ctrl As Control)

Dim i As Long

Select Case TypeName(ctrl)

 

Case Is = "Listbox"

    For i = 0 To ctrl.ListCount - 1

        ctrl.Selected(i) = False

    Next

Case Is = "ComboBox"

    For i = 0 To ctrl.ListCount - 1

        ctrl.Selected(i) = False

    Next

Case Is = "TextBox"

        Ctrl=""

Case Is = "CheckBox"

    ctrl = False

Case Else

    MsgBox "Fix code!"

End Select

 

End Sub



More information about the AccessD mailing list