Okay, I'm seeing single and double quotes swimming through the air and I still can't figure out the syntax for what I'm trying to do. Before I start talking to the wee people in my head I thought I'd bring my question here.
I'm trying to construct a string to use with the DoCmd.Runsql vba command that will allow me to pass a variable to it as I loop through a list of prior query names and append the results to a table. I have a string already constructed that explicitly lists the query to use. The problem I'm having is constructing the string to see and use the variable. My original string is below:
Code:
dim SQLstr as string
SQLstr = "INSERT INTO FieldListTable ( FieldPickDate, FieldNumber, fieldname, ControlName, OORField, ControlTag ) " & _
"SELECT FieldPickDate, DCount(""id"",""UFO2_IsolatorFieldPollQ"",""id <= "" & [id]) AS FieldNumber, ControlSource, " & _
"ControlLabel, ControlOOR, ControlTag FROM UFO2_IsolatorFieldPollQ"
DoCmd.RunSQL SQLstr
This works fine and does exactly what I'm looking for with the UFO2_IsolatorFieldPollQ query. What I now want to do is use a variable to insert other text (stored in a table) where the Isolator text is; such as...
UFO2_variablestringFieldPollQ
I'm trying to build this append string so that it can dynamically change the queries it runs off of as query names change or or added to a list (table).
I'm using another string variable to hold the new text and, no matter how I include it, I can't get it to see the variable or it sees the variable but my DLookup function isn't seen as a function. I'm sure it's got something to do with my use (or lack of) quotes and the combination of double and single quotes. I'm looking for a string in the form of what I have below (I realize the quotes around the variable aren't correct).
Code:
dim SQLstr as string
dim Areastr as string
Areastr = dlookup (another table)
SQLstr = "INSERT INTO FieldListTable ( FieldPickDate, FieldNumber, fieldname, ControlName, OORField, ControlTag ) " & _
"SELECT FieldPickDate, DCount(""id"",""UFO2_" & Areastr & "FieldPollQ"",""id <= "" & [id]) AS FieldNumber, ControlSource, " & _
"ControlLabel, ControlOOR, ControlTag FROM UFO2_" & AreaStr & "FieldPollQ"
DoCmd.RunSQL SQLstr
Any ideas? Or am I totally incorrect in thinking I can create a string for this operation without specifically naming the main query?