Combo Box Code Find Record

sammy204

Registered User.
Local time
, 21:05
Joined
Jun 14, 2008
Messages
20
Hi

I have a form with a button which opens and passes a value to a second form. The second forms on load event says put that value in combo box 2.

Combobox2 when an item is selected will find that record on the form.


However because I havent selected it myself, only told access to put the value in combobox2, it does not go to the record I want. I want the form to find the record with the value in the combo box.

The value is not set as primary key but should always be unique.

Any Ideas?
 
Don't use the combo box. Set the record with a filter. Keep the combo box if you want it for something else but it is not a good way to select the opening record
 
Hi Thanks for the reply

but I dont know anything about filters to be honest.

How should I set the record with a filter?

Would this go with the docmd.openform part on the first form? or in the onload part of the second?

How do I set up the filter?

Thanks
 
Last edited:
Are you using Open Args to pass the value initially?
 
Hi

Yes I am passing the value from form1 to form2 using openargs

Form1 has a button which on the click event runs something like

docmd.openform "form2",,,,,,me.text2.value


How do I use the filter then? To show only the record where one field has the value of me.text2.value ? It is not the primary key though

Thanks
 
Hi

Yes I am passing the value from form1 to form2 using openargs. Form1 has a button which on the click event runs something like

docmd.openform "form2",,,,,,me.text2.value

How do I use the filter then? To show only the record where one field has the value of me.text2.value ? It is not the primary key though

Thanks

OK, You are passing it via OpenArgs. Now how are you getting the value in the first place?
 
The original value on form1 comes from a combo box which shows the records on form2. It might sound odd but I think it needs to be this way because of some of the things I am doing with the form. E.g. there are 3 buttons on form 1, one for new orders, one for current orders and one for prebooked orders. And I need to link to form2 from a different form.

But using the value passed to form2 how can I filter the records to show only the records with the value that was passed in the table number field?

It needs to kind of work like a combo box on form2 that finds a selected record on the form.

Hope it made sense lol
 
First, get rid of the OpenArgs, you don't need it...

Put this code on your button:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = NameOfForm2

stLinkCriteria = "[NameOfFieldYouAre Matching]=" & "'" & Me![ComboListName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click

End Sub
 
wow thankyou that works brilliantly.

Really appreciate your help

Thanks Again :D
 

Users who are viewing this thread

Back
Top Bottom