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

QueryDef and Populating combo Box

Status
Not open for further replies.

marydn

Programmer
Mar 26, 2001
152
US
I have created a querydef that passes parameters and now I want to take that data in the form of a recordset and populate a combo box. Can anyone tell me what I am doing wrong?

Dim db As Database
Dim qd As QueryDef

Set db = CurrentDb

Set qd = db.CreateQueryDef("Sites")
qdtext = "PARAMETERS Stand text, st text; "

qdtext = qdtext & "SELECT * FROM table WHERE " & _
"siteStanding = stand AND SiteType = st"

qd.Sql = qdtext

Dim rs As Recordset
Dim strlist As String

Set qd = db.QueryDefs("Sites")

qd!stand = "Owned"
qd!st = "Managed"

Set rs = qd.OpenRecordset(dbOpenSnapshot)

With rs
Do While Not .EOF
strlsit = strlist & rs(0) & "," & rs(1)
.MoveNext
Loop
End With

cboSite.rowsource = strlist (This part doesn't work)


rs.Close
db.Close


Any help would be greatly appreciated.


 
I bet your row source type is set incorrectly.
It looks like you are just giving it a list of values.
Make sure the listbox's RowSourceType is set to Value List and not Table/Query or Field List.
 
I tried that and it still doesn't work.

Thanks.
 
The items in the value list need to be surrounded by quotes so if you change your code to the following:



With rs
Do While Not .EOF
strlsit = strlist & rs(0) & "';'" & rs(1)
.MoveNext
Loop
End With

strlist = "'" & strlist & "'"

cboSite.rowsource = strlist

Hope this helps,
Shannon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top