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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing param to query from combo-box - how to? 1

Status
Not open for further replies.

lauraSatellite

Technical User
Jul 22, 2004
35
IE
I have a form that is based on the following query:

SELECT *
FROM Address
WHERE Area=[?];

Also on this form is a combo-box set up with the following values: North, South, East, West. These values correspond to the possible values stored in the 'Area' field of the Address table.

When I change the value displayed in the combo-box, i want the corresponding group of records to be displayed. I have attached the following code to the onChange of the combo-box:

Me.Requery = Me.combobox.Value()

I am relatively new to procedures, any help with this would be very much appreciated.
 
The approach I'd take, given what you've said is:


In the Form's On_Load event put
Code:
Call UpdateSource


and then have a sub
Code:
Private Sub UpdateSource()
If IsNull(comboBoxName) Then
    Me.RecordSource = "SELECT * FROM Address "
Else
    Me.RecordSource = "SELECT * FROM Address " _
                    & "WHERE Area = '" & ComboBoxName & "'"
End If
Me.Requery
End Sub

and put the same
Code:
Call UpdateSource

in the combo box's AfterUpdate event too.


You don't need the Me. before the combobox name
(It sould be Me! if you use it anyway; but it is not needed )

You certainly don't want to be using the .Value property




'ope-that-'elps.




G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Hi

Make Recordsource of the form:

SELECT *
FROM Address
WHERE Area=Forms!MyFormName!ComboBox OR IsNull(Forms!MyFormName!ComboBox );

in After Update event of combo box put

Me.Requery

In OnOpen Event of Form put

ComboBox_AfterUpdate

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thanks very much, i have this working now. I used the Private Sub UpdateSource() solution and it worked perfectly. I attached the procedure that you specified to the onChange event of the combo-box. Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top