Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set combo box by hidden column 1

Status
Not open for further replies.

CaptainBob007

Programmer
Dec 20, 2003
42
0
0
US
Hi -

I have a combo box with 2 columns, the first one is hidden and the second is not. So a user can select an address, and the (hidden) ID for the property is selected behind the scenes, and the form works beautifully.

Now I am trying to open this form from another form by passing in the ID number. I would like to have the combo box set itself to the proper address (and display that address) by using the ID on loading. I can't figure it out.

Basically I am trying to come up with VB code (or whatever is necessary) to take in a hidden value for a combo box and get the combo box to output its associated non-hidden value for that.

Any suggestions?
 
How are ya CaptainBob007 . . .

In the [blue]On Load[/blue] event of the form try this:
Code:
[blue]   Dim idx As Integer, Cbx As ComboBox
   
   Set Cbx = Me![purple][b]ComboboxName[/b][/purple]
   Cbx.SetFocus
   
   For idx = 0 To Cbx.ListCount - 1
      If Cbx.ItemData(idx) = [purple][b]YourPassedID[/b][/purple] Then
         Cbx.Text = Cbx.Column(1, idx)
         Exit For
      End If
   Next
   
   Set Cbx = Nothing[/blue]
The key here is how your passing [purple]ID[/purple] and wether its numeric/string. This is what [purple]YourPassedID[/purple] gets replaced with.

[blue]Your Thoughts?[/blue]

Calvin.gif
See Ya! . . . . . .
 
And what about simply something like this (Load event procedure of 2nd form):
Me![combo name] = Forms![name of 1st form]![combo name]

Assumption: both combos have compatible RowSource.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks so much AceMan. I appreciate your help too PHV, but I had tried your solution before and it just wasn't working for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top