One thing you can do to make life simpler. Use an alias for the table name.
IT doesn't make a lot of difference in a query with only one since you can refer
to fields without the table name prefixed.
SELECT DISTINCTROW First(A.date) AS [date Field],
First(A.number) AS [number Field],
First(A.reason) AS [reason Field],
First(A.[issued to]) AS [issued to Field],
Count(A.date) AS NumberOfDups
FROM History_Table_Birdsall AS A
GROUP BY A.date, A.number,
A.reason, A.[issued to]
HAVING (((Count(A.date))>1) AND
((A.[issued to]))>=0));
Then all you have to replace in the string is the one instance of a table name.
Dim strTableName as string
Dim strSQL as string
strTableName = "History_Table_BirdsAll"
StrSQL = "SELECT DISTINCTROW First(A.date) AS [date Field],
First(A.number) AS [number Field],
First(A.reason) AS [reason Field],
First(A.[issued to]) AS [issued to Field],
Count(A.date) AS NumberOfDups
FROM [" & strTableName "] & AS A
GROUP BY A.date, A.number,
A.reason, A.[issued to]
HAVING (((Count(A.date))>1) AND
((A.[issued to]))>=0))"
I would observe that I think your query is quite strange. I would write it as
SELECT A.date AS [date Field],
A.number AS [number Field],
A.reason AS [reason Field],
A.[issued to] AS [issued to Field],
Count(A.date) AS NumberOfDups
FROM History_Table_Birdsall AS A
WHERE A.[Issued To] >= 0
GROUP BY A.date, A.number,
A.reason, A.[issued to]
HAVING Count(A.date)>1
Thanks, I have gotten that far but having the form and combo box record (and
row) source change as different tables are identified. I have been trying to
have the queries choose a table in a IF-Then stament:
SELECT DISTINCTROW First(History_Table_Birdsall.date) AS [date Field],
First(History_Table_Birdsall.number) AS [number Field],
First(History_Table_Birdsall.reason) AS [reason Field],
First(History_Table_Birdsall.[issued to]) AS [issued to Field],
Count(History_Table_Birdsall.date) AS NumberOfDups
FROM History_Table_Birdsall
GROUP BY History_Table_Birdsall.date, History_Table_Birdsall.number,
History_Table_Birdsall.reason, History_Table_Birdsall.[issued to]
HAVING (((Count(History_Table_Birdsall.date))>1) AND
((Count(History_Table_Birdsall.[issued to]))>=0));
[MVP] S.Clark said:
I think you mean that the tablename for the query is selectable via the
option group. Because Option groups are number based, you would need to do
an IF...Then or Select Case to discern.
dim strTable as string
Select Case ogTable
case 1 : strTable = "History_Table_Birdsall"
case 2: strTable = "HIstory_Table_Cascade"
End Select
strSql = "Select * from " & strTable & " WHERE ..."
Use the strSql value to populate a form, subform, or report.
--
Steve Clark, Access MVP
FMS, Inc
http://www.fmsinc.com/consulting
Professional Access Database Repair
*FREE* Access Tips:
http://www.fmsinc.com/free/tips.html