N
nxqviet
Hi all,
I'm trying to create queries using VBA. The user will work through a
form in order to create a custom query. I've been spending a whole day
on this code trying to figure out what is wrong with it, but I
couldn't. Since there is an error in this stSQL, the SQL of the query
can not be replaced. Please help and Thank You very much for your
time. The code is as follow...
--------------------------------------------------------------------------------------------------------------------------------------
Dim Alias As Variant
Dim Product1 As Variant
Dim BeginDate As Variant
Dim EndDate As Variant
Dim stSQL As String
Alias = AliasCb.Value
Product1 = FieldA.value
BeginDate = DateBeginField.Value
EndDate = DateEndField.Value
stSQL = "SELECT TABLE_CUSTOMER.ALIAS, TABLE_PACK.NAME,
Count(TABLE_RECORDS.PACK_ID) AS CountOfPACK_ID" & _
"FROM TABLE_PACK INNER JOIN ((TABLE_CUSTOMER INNER JOIN TABLE_RECORDS
ON TABLE_CUSTOMER.CUSTOMER_ID = TABLE_RECORDS.CUSTOMER_ID)" & _
"INNER JOIN TABLE_PACK_DETAIL ON TABLE_RECORDS.PACK_ID =
TABLE_PACK_DETAIL.PACK_ID) ON TABLE_PACK.PACK_ID =
TABLE_RECORDS.PACK_ID" & _
"WHERE (((TABLE_CUSTOMER.ALIAS)= " & Alias & ") AND
((TABLE_RECORDS.EXPORT_DATE) Between " & BeginDate & " And " & EndDate
& ") AND" & _
"((TABLE_PACK_DETAIL.VERIFICATION_SUBJECT_ID)= " & Product1 & ") AND
((TABLE_RECORDS.PACK_ID) Is Not Null))" & _
"GROUP BY TABLE_CUSTOMER.ALIAS, TABLE_PACK.NAME;"
CurrentDb.QueryDefs("qryTemplate").SQL = stSQL
CurrentDb.QueryDefs.Refresh
--------------------------------------------------------------------------------------------------------------------------------------
THANK YOU!
V_
I'm trying to create queries using VBA. The user will work through a
form in order to create a custom query. I've been spending a whole day
on this code trying to figure out what is wrong with it, but I
couldn't. Since there is an error in this stSQL, the SQL of the query
can not be replaced. Please help and Thank You very much for your
time. The code is as follow...
--------------------------------------------------------------------------------------------------------------------------------------
Dim Alias As Variant
Dim Product1 As Variant
Dim BeginDate As Variant
Dim EndDate As Variant
Dim stSQL As String
Alias = AliasCb.Value
Product1 = FieldA.value
BeginDate = DateBeginField.Value
EndDate = DateEndField.Value
stSQL = "SELECT TABLE_CUSTOMER.ALIAS, TABLE_PACK.NAME,
Count(TABLE_RECORDS.PACK_ID) AS CountOfPACK_ID" & _
"FROM TABLE_PACK INNER JOIN ((TABLE_CUSTOMER INNER JOIN TABLE_RECORDS
ON TABLE_CUSTOMER.CUSTOMER_ID = TABLE_RECORDS.CUSTOMER_ID)" & _
"INNER JOIN TABLE_PACK_DETAIL ON TABLE_RECORDS.PACK_ID =
TABLE_PACK_DETAIL.PACK_ID) ON TABLE_PACK.PACK_ID =
TABLE_RECORDS.PACK_ID" & _
"WHERE (((TABLE_CUSTOMER.ALIAS)= " & Alias & ") AND
((TABLE_RECORDS.EXPORT_DATE) Between " & BeginDate & " And " & EndDate
& ") AND" & _
"((TABLE_PACK_DETAIL.VERIFICATION_SUBJECT_ID)= " & Product1 & ") AND
((TABLE_RECORDS.PACK_ID) Is Not Null))" & _
"GROUP BY TABLE_CUSTOMER.ALIAS, TABLE_PACK.NAME;"
CurrentDb.QueryDefs("qryTemplate").SQL = stSQL
CurrentDb.QueryDefs.Refresh
--------------------------------------------------------------------------------------------------------------------------------------
THANK YOU!
V_