Select combobox item by invisible column when Limit To List = No

  • Thread starter JohnM77 via AccessMonster.com
  • Start date
J

JohnM77 via AccessMonster.com

I have a combobox that has two columns: UserID and Name. The following are
pertinent properties:

Row Source/Type = Table/Query
Column Count = 2
Column Widths = 0"; 3"
Bound Column = 2
Limit To List = No

I wish to programmatically select an item from the combobox based on UserID
(numeric). However, because column 2 (Name) is the bound column (required in
order to set Limit to List = No, which is necessary), I can't use Combobox.
Value = UserID, because the UserID column is not bound. Since the Column
property is read-only, I can't set it using Combobox.Column(0) = UserID.

Are there any options aside from querying for the Name corresponding to the
UserID and setting Combobox.Value = Name?

Thanks!
-John
 
J

Jack Leach

I think a syntax such as Me.ComboBox.Column(0).Value would work (probably the
same for a listbox)

hth


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

never mind... i don't know how I manged to read your post and not see that
you already tried that.

Please excuse my stupidity
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
D

Douglas J. Steele

Dim lngLoop As Long

For lngLoop = 0 To (Me.Combobox.ListCount - 1)
If Me.Combobox.Column(0, lngLoop) = UserId Then
Me.Combo0 = Me.Combo0.Column(1, lngLoop)
Exit For
End If
Next lngLoop
 
J

JohnM77 via AccessMonster.com

Thanks, Doug. That works well. I had actually thought of that option of
looping through all items, but I figured for sure there was a more elegant
way. So I take it there's no direct command for selecting a combobox item
based on a non-bound column value?

Thanks,
John
Dim lngLoop As Long

For lngLoop = 0 To (Me.Combobox.ListCount - 1)
If Me.Combobox.Column(0, lngLoop) = UserId Then
Me.Combo0 = Me.Combo0.Column(1, lngLoop)
Exit For
End If
Next lngLoop
I have a combobox that has two columns: UserID and Name. The following are
pertinent properties:
[quoted text clipped - 20 lines]
Thanks!
-John
 
D

Douglas J. Steele

Not to the best of my knowledge. The List Box has a Selected property, but
the Combo Box doesn't.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


JohnM77 via AccessMonster.com said:
Thanks, Doug. That works well. I had actually thought of that option of
looping through all items, but I figured for sure there was a more elegant
way. So I take it there's no direct command for selecting a combobox item
based on a non-bound column value?

Thanks,
John
Dim lngLoop As Long

For lngLoop = 0 To (Me.Combobox.ListCount - 1)
If Me.Combobox.Column(0, lngLoop) = UserId Then
Me.Combo0 = Me.Combo0.Column(1, lngLoop)
Exit For
End If
Next lngLoop
I have a combobox that has two columns: UserID and Name. The following
are
pertinent properties:
[quoted text clipped - 20 lines]
Thanks!
-John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top