[SOLVED] INSERT INTO SELECT statement
Hello Experts,
Here's my challenge. I have an append query that contains an IIF statement. I want to code that into a VBA function. The SQL view of the query looks like this:
What I wrote for the VBA code is this:
Where it chokes is on the IIF statement with the double-quotes in it. I've tried several combinations with single quotes and double double-quotes. I'm just not getting it. Can any of you please tell me what I'm doing wrong? I know I'm doing something wrong. I just can't figure out what. :banghead:
Thank you,
Marvin M
Hello Experts,
Here's my challenge. I have an append query that contains an IIF statement. I want to code that into a VBA function. The SQL view of the query looks like this:
Code:
INSERT INTO tmpAvailInv ( NUID, Inv_Name, F_Name, M_Name, L_Name, Role )
SELECT tblPeople.NUID, tblPeople.[F_name] & IIf(IsNull([M_Name])," "," " & [M_Name] & " ") & [L_Name] AS Inv_Name, tblPeople.F_Name, tblPeople.M_Name, tblPeople.L_Name, tblPeople.Role
FROM tblPeople
WHERE (((tblPeople.Role)="Investigator") AND ((tblPeople.Archive)=False));
Code:
Dim strSQL As String
Dim db As Database
Set db = CurrentDb
strSQL = "INSERT INTO tmpAvailInv ( NUID, Inv_Name, F_Name, M_Name, L_Name, Role ) " & _
SELECT tblPeople.NUID, " & _
tblPeople.[F_name] & IIf(IsNull([M_Name])," "," " & [M_Name] & " ") & [L_Name] AS Inv_Name, " & _
tblPeople.F_Name, tblPeople.M_Name, tblPeople.L_Name, tblPeople.Role " & _
FROM tblPeople " & _
WHERE (((tblPeople.Role)="Investigator") AND ((tblPeople.Archive)=False));"
db.Execute (strSQL)
db.Close
Thank you,
Marvin M
Last edited: