Hi folks,
Could someone point out what I'm doing wrong with this query? The basics ran OK in the query grid and it compiles but I get the error when I try to run it within VBA ...
Dim qdf2 As DAO.QueryDef, strq As String
strq = strq & " SELECT TOP 6 tblResults.pos, tblResults.membername "
strq = strq & " FROM (tblRace INNER JOIN tblSeries ON [tblRace].[seriesID] = [tblSeries].[seriesID]) INNER JOIN tblResults ON [tblRace].[raceauto] = [tblResults].[raceID] "
strq = strq & " WHERE ((([tblSeries].[seriesID]) = 45) And (([tblResults].[membername]) = " & strname & " ))"
strq = strq & " ORDER BY [tblResults].[pos];"
Set qdf2 = db.CreateQueryDef("qrywall2", strq)
(strname is a string variable obtained earlier in the code)
The full error code text is
Run-time error '3075'
Syntax error 'missing operator' in query expression
'((([tblSeries].[seriesID]) = 45) And (([tblResults].[membername]) = Fred Bloggs))'.
(strname = Fred Bloggs is correct)
When I get this to work, I plan to replace the 'test' value of TOP and seriesID with variable values and then
DSUM the results to get the total value of pos for the Top N values -
- such as intval = DSum(pos, "qrywall2") ... though I suspect there is a much more effetive way to achieve all this in one query.
Grateful for your thoughts and best regards to all
Could someone point out what I'm doing wrong with this query? The basics ran OK in the query grid and it compiles but I get the error when I try to run it within VBA ...
Dim qdf2 As DAO.QueryDef, strq As String
strq = strq & " SELECT TOP 6 tblResults.pos, tblResults.membername "
strq = strq & " FROM (tblRace INNER JOIN tblSeries ON [tblRace].[seriesID] = [tblSeries].[seriesID]) INNER JOIN tblResults ON [tblRace].[raceauto] = [tblResults].[raceID] "
strq = strq & " WHERE ((([tblSeries].[seriesID]) = 45) And (([tblResults].[membername]) = " & strname & " ))"
strq = strq & " ORDER BY [tblResults].[pos];"
Set qdf2 = db.CreateQueryDef("qrywall2", strq)
(strname is a string variable obtained earlier in the code)
The full error code text is
Run-time error '3075'
Syntax error 'missing operator' in query expression
'((([tblSeries].[seriesID]) = 45) And (([tblResults].[membername]) = Fred Bloggs))'.
(strname = Fred Bloggs is correct)
When I get this to work, I plan to replace the 'test' value of TOP and seriesID with variable values and then
DSUM the results to get the total value of pos for the Top N values -
- such as intval = DSum(pos, "qrywall2") ... though I suspect there is a much more effetive way to achieve all this in one query.
Grateful for your thoughts and best regards to all