Query String

radek225

Registered User.
Local time
Today, 07:13
Joined
Apr 4, 2013
Messages
307
I want to write a query string from a query:
Code:
SELECT *
FROM tblZmiany
WHERE datazmiany = #25-11-2015# or (datazmiany > #25-11-2015# and (datazmiany = #26-11-2015# or datazmiany < #26-11-2015#));

but
#25-11-2015# = zakresPoczatkowy
#26-11-2015# = zakresKoncowy

So I tried to write it but doesn't work properly

Code:
dim zakresPoczatkowy as date
dim zakresKoncowy as date
dim strSQL as date
dim rst as dao.recordset

strSQL = "Select * from tblZmiany where datazmiany=" & ZakresPoczatkowy & " or (datazmiany>" & ZakresPoczatkowy & " and (datazmiany=" & zakresKoncowy & " or datazmiany<" & zakresKoncowy & ")" & ")"
set rst = currentdb.openrecordset(StrSQL)
....

What should I change in my strSQL?
 
your date may display in your regional setting, but access query works on US date format:

dim strSQL as string
dim rst as dao.recordset

strSQL = "Select * from tblZmiany where datazmiany=#" & Format(ZakresPoczatkowy,"mm/dd/yyyy") & "# or (datazmiany>#" & Format(ZakresPoczatkowy,"mm/dd/yyyy") & "# and (datazmiany=#" & Format(zakresKoncowy,"mm/dd/yyyy") & "# or datazmiany<#" & Format(zakresKoncowy,"mm/dd/yyyy") & "#)" & ")"
set rst = currentdb.openrecordset(StrSQL)
 

Users who are viewing this thread

Back
Top Bottom