View Full Version : Multiple INs construction


StarvinMarvin
03-11-2010, 03:28 PM
This isn't compiling for me.... I've tried changing parenthesis around and such but no go:

Public Sub Doit()
Dim strSQL As String
strSQL = "SELECT requests.lastname, requests.firstname, requests.star, requests.seniority_dt, requests.reqdate, requests.reqtime " & _
"INTO Assignments " & _
"FROM requests " & _
"WHERE (not exists (requests.emp_no)) and requests.emp_no IN " & _

"(SELECT TOP 2 requests.seniority_dt, requests.birth_dt, requests.emp_no, requests.reqdate, requests.reqtime " & _
"FROM requests " & _
"ORDER BY requests.seniority_dt, requests.birth_dt " & _
"WHERE (((Requests.reqdate) In ("SELECT requests.reqdate, requests.reqtime " & _
"FROM requests;")) AND ((Requests.reqtime) In ("SELECT requests.reqdate, requests.reqtime " & _
"FROM requests;"))) " & _

"(SELECT requests.reqdate, requests.reqtime " & _
"FROM requests;"

DoCmd.RunSQL strSQL
End Sub
***************************************

Or is it that I can't do multiple INs like this?

The flow I'm going for is this:

Select the specific date and time, then select the top 2 people in seniority who chose that date and time, then insert the info for those top 2 people into the assignments table if their employee numbers aren't already in the table.

pbaldy
03-11-2010, 04:46 PM
Why have this in VBA at all? There's nothing dynamic about it. I would just execute a saved query. That said, presuming those extra blank lines aren't actually in the code, you've got random quotes in the middle of your strings, like right before the inner SELECT statements, and others. You don't want any quotes inside other quotes. You need matched sets of quotes, joined by ampersands:

"SELECT..." & "More here" & "even more"

ajetrumpet
03-11-2010, 05:42 PM
aside from what Paul said, let us not forget that you can't run a select qry in code anyway.

and just reading through your statement , i'm almost positive there is syntax errors abound anyway.

pbaldy
03-11-2010, 06:44 PM
let us not forget that you can't run a select qry in code anyway.

I agree that there are syntax errors, but it is (or intended to be) an action query that could be run from code. You probably missed the INTO:

SELECT...INTO...

ajetrumpet
03-11-2010, 07:14 PM
I agree that there are syntax errors, but it is (or intended to be) an action query that could be run from code. You probably missed the INTO:

SELECT...INTO...

laughing....my bad of course. thanks so much!!