Setting a comboBox recordsource to a parameter query or recordset

G

G

I am trying to set the recordsource of a combobox a parameter query with
the combo box wizard, but get an error message that one of the parameter
will not be assigned a value. This is understandable, as the query is a one
parameter query who value is equals to a field on a form.
Is there a way to do this?


I tried writing a procedure that would open up a recordset and get the same
data as the query then set the combobox recordsource equal to the Recordset,
but this did not work.

Any ideas?

Here is the code:
Private Sub Form_Open(Cancel As Integer)
Dim RS As Recordset
Dim strSQL As String


Set RS = New ADODB.Recordset

strSQL = "SELECT Part_ID FROM ESIDB.dbo.SOFSN SOFSN WHERE
(Serial_NUmber)='" & Forms("FrmRMARequest")("SN") & "'"
RS.Open strSQL,
"Provider=SQLOLEDB;server=sqlserver2;uid=crystal;pwd=esi;DSN=esi",
adOpenStatic

Me("ComboMultipleUnits").RecordSource = RS

End Sub
 
G

Gerald Stanley

A combo box does not have a RecordSource property.

Assuming that the form on which the combo resides is not
the same form as that on which the control used in the
query resides, you should be able to use something along
the lines of
Me("ComboMultipleUnits").RowSource = "SELECT Part_ID FROM
ESIDB.dbo.SOFSN SOFSN WHERE (Serial_NUmber)='" &
Forms("""FrmRMARequest""")!("""SN""") & "'"
in the form's Load eventHandler

Hope This Helps
Gerald Stanley MCSD
 
G

G

Gerlad,
Thanks for the response. I wrote that snippet early in the morning and was
think rowsource, but wrote recordset. Thanks.

G
 

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