Unbound Combo Box - which row

Webskater

Registered User.
Local time
Today, 02:43
Joined
Aug 29, 2006
Messages
14
Hello all

I'm new to Access so sorry if this is stupid - I have looked everywhere!

I have an unbound combo box on a form that is populated in the onload event of the form by setting the rowsource to a query based on the companyID on the form. The query gets me a list of contacts at that company.

So, after the form is loaded the combo box (if dropped down) might show:

1 Fred Smith
7 Jim Jones
9 Arthur Askey

The first column contains the ContactID.

My question is .... when the form loads I know the ContactID of the person I am looking at. If that person is 'Jim Jones' and I have a field on the form which contains Jim Jones ContactID of 7 - how can I get the combo box to be showing the 'Jim Jones' row?

(I don't what to bind the combo box to anything as I want to use it just to filter which contact I am looking at - not change the ContactID)

I guess I want to loop through the combo box saying 'If the contactID of this row = the ContactID on the form - select this row' - but I can't find the syntax anywhere.

Thanks for any help.
 
Last edited:
In the OnChange property of the combo box

Dim strFilter as String
strFilter = "[ContactID] = '" & Me.YourComboBox.Column(0)
Me.Filter = strFilter
Me.FilterOn = True

Hope this helps.
 
jkl0 said:
In the OnChange property of the combo box

Dim strFilter as String
strFilter = "[ContactID] = '" & Me.YourComboBox.Column(0)
Me.Filter = strFilter
Me.FilterOn = True

Hope this helps.

Hi, thanks for your reply.

Not sure if it gives me what I want. Often you use a combo box to select which record(s) to display.

I want to do the opposite. When a form opens I know which record I want to display - but I want to get an unbound combo box on that form to show which record is selected.

So I know a contactID and my combo box might have 4 rows in it. The ContactID of the 3rd row might be the ContactID of the record being shown on the form - how can I say 'make this combo box display the row whose ContactID matches the ContactID on the form?'

Thanks again for any input.
 
I think this is what you want?

Edit: Re-reading your question:

I'm not sure if I understand you right, but it sounds like the form with that combobox is a pop up which may open based on other form's selection, and you want to make sure that the combobox is properly synchronized with whatever record the form opened with?

If so, in form's OnOpen event, you simply only need this:

Code:
Me.MyCombobox= Me.ContactID

As long it has a rowsource, it won't matter whether it's bound or not; it'll do the trick just fine.

HTH.
 
Last edited:
Banana said:
I think this is what you want?

Edit: Re-reading your question:

I'm not sure if I understand you right, but it sounds like the form with that combobox is a pop up which may open based on other form's selection, and you want to make sure that the combobox is properly synchronized with whatever record the form opened with?

If so, in form's OnOpen event, you simply only need this:

Code:
Me.MyCombobox= Me.ContactID

As long it has a rowsource, it won't matter whether it's bound or not; it'll do the trick just fine.

HTH.

Brilliant! That did the trick. I read the Access documentation until I was blue in the face and couldn't find that. I assumed I was going to have to loop through the combo box rows etc but couldn't find the syntax.

Thanks very much for both answers.
 

Users who are viewing this thread

Back
Top Bottom