RecordSet <> Query

G

Guest

I feel like I have entered the twilight zone. I want a recordset that
contains the SCR_ID, SCR_Element and SCR_State for the specific SCR_ID's
selected by the user. When I execute the code I can see that what I have for
strSQL returns exactly what I want. But for some reason the RecordSet
contains every SCR_ID in the table (4,000 of them!) not just the specific
SCR_ID's I can see in strSQL. SCR_ID is a text field.

Here is part of the code (storing only the SCR_ID for now):
strSQL = "SELECT SCR_ID, SCR_State, SCR_Element FROM tblSCR WHERE SCR_ID = "
& strSCRs
Debug.Print strSQL
' Returns:
' SELECT SCR_ID, SCR_State, SCR_Element FROM tblSCR WHERE SCR_ID = '6071' OR
'6072'
Set db = CurrentDb()
Set rstSCRs = db.OpenRecordset(strSQL, dbOpenSnapshot)

Do While Not rstSCRs.EOF
varConcat = varConcat & rstSCRs("SCR_ID") & "; "
rstSCRs.MoveNext
Loop
Debug.Print varConcat
' Returns every SCR_ID in the table

I cannot figure out what I am doing wrong. Any help would be appreciated.

Thank you,
Judy
 
G

Guest

I guess it took reading my own question to figure out the answer.
SELECT SCR_ID, SCR_State, SCR_Element FROM tblSCR WHERE SCR_ID = '6071' OR
'6072'
will always return true for the second condition. I need another "SCR_ID ="
so that I will have:
SELECT SCR_ID, SCR_State, SCR_Element FROM tblSCR WHERE SCR_ID = '6071' OR
SCR_ID = '6072'

Problem solved!
 

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