SQL Statement

  • Thread starter Thread starter news
  • Start date Start date
N

news

Is it possible to have a variable in the HAVING statement instead of the
field [FLDVST.Dt_Visited]? When I use a variable and run the statement the
query ask for a parameter for the variable, it think it's a field. When I
look at the design of the query it added the variable as a field. Thanks.


Set db = CurrentDb()
strSQLSelect = _
"SELECT " _
& "[TW: ProvidersContractEffDate].[Key Name], " _
& "FROM [TW: ProvidersContractEffDate]
& "GROUP BY [TW: ProvidersContractEffDate].[Key Name]

& "HAVING (((FLDVST.Dt_Visited) " _

& "Between #" _

& [Forms]![TW: Reports]![StrDate] & "# " _

& "And " _

& [Forms]![TW: Reports]![EndDate] & "#) ")) _
 
Your SQL statement is incomplete, but what you do is concatenate the value
of the variable in the string (see your HAVING line):

Set db = CurrentDb()
strSQLSelect = _
"SELECT " _
& "[TW: ProvidersContractEffDate].[Key Name], " _
& "FROM [TW: ProvidersContractEffDate]
& "GROUP BY [TW: ProvidersContractEffDate].[Key Name]

& "HAVING (((" & MyVariableName & ") " _

& "Between #" _

& [Forms]![TW: Reports]![StrDate] & "# " _

& "And " _

& [Forms]![TW: Reports]![EndDate] & "#) ")) _
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SQL Statement 2
IF, ELSEIF STATEMENTS 4
Normalization Question 6
Insert Worksheets based on column data. 10
Make Table Query 6
Example Of VBA SQL Statement 0
update queries 2
Writting a xml file 2

Back
Top