M
Mr. Bud
Hi and TIA. What I'm wondering is can you use aquery name in place of a
table name when building an sql statement in code? Example below can I
replace MyTable with MyQuery. It bombs out on me when I run the code. My
goal is to creat several Union queries in my db. Have the user select
tables on my form to use in the results and depending on what they select I
will use that saved Union query in place of the table name (MyTable)
below.Thanks for your time.
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryMultiSelect")
If Me!lstUIC_ID.ItemsSelected.Count > 0 Then
For Each varItem In Me!lstUIC_ID.ItemsSelected
strCriteria = strCriteria & "MyTable.UIC = " & Chr(34) _
& Me!lstUIC_ID.ItemData(varItem) & Chr(34) & "OR "
Next varItem
strCriteria = Left(strCriteria, Len(strCriteria) - 3)
Else
strCriteria = "MyTable.UIC Like '*'"
End If
strSQL = "SELECT * FROM MyTable" & _
"WHERE " & strCriteria & ";"
qdf.SQL = strSQL
DoCmd.OpenQuery "9h1_qryMultiSelect"
table name when building an sql statement in code? Example below can I
replace MyTable with MyQuery. It bombs out on me when I run the code. My
goal is to creat several Union queries in my db. Have the user select
tables on my form to use in the results and depending on what they select I
will use that saved Union query in place of the table name (MyTable)
below.Thanks for your time.
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryMultiSelect")
If Me!lstUIC_ID.ItemsSelected.Count > 0 Then
For Each varItem In Me!lstUIC_ID.ItemsSelected
strCriteria = strCriteria & "MyTable.UIC = " & Chr(34) _
& Me!lstUIC_ID.ItemData(varItem) & Chr(34) & "OR "
Next varItem
strCriteria = Left(strCriteria, Len(strCriteria) - 3)
Else
strCriteria = "MyTable.UIC Like '*'"
End If
strSQL = "SELECT * FROM MyTable" & _
"WHERE " & strCriteria & ";"
qdf.SQL = strSQL
DoCmd.OpenQuery "9h1_qryMultiSelect"