Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open form criteria between dates

Status
Not open for further replies.

ben1234zz

MIS
May 12, 2008
71
GB
Hi

We are trying to open a form showing items from the last 7 days, we have the below VBA criteria:

stLinkCriteria =
"([DateCreated] BETWEEN #" & Format(DateAdd("d", -7, Date), "d/m/yyyy") & _
"# AND #" & Format(Date, "d/m/yyyy") & "#) OR ([InvoiceDate] BETWEEN #" & _
Format(DateAdd("d", -7, Date), "d/m/yyyy") & "# AND #" & Format(Date, "d/m/yyyy") & "#)"

This is the result, but it says there is an error near #

([DateCreated] BETWEEN #27/7/2009# AND #3/8/2009#) OR ([InvoiceDate] BETWEEN #27/7/2009# AND #3/8/2009#)

I cant see the issue.

Thanks
B
 
These expressions expect the date in format of m/d/yyyy.

Code:
stLinkCriteria =   "([DateCreated] BETWEEN #" & Format(DateAdd("d", -7, Date), "m/d/yyyy") & _  
   "# AND #" & Format(Date, "m/d/yyyy") & "#) OR ([InvoiceDate] BETWEEN #" & _  
   Format(DateAdd("d", -7, Date), "m/d/yyyy") & "# AND #" & Format(Date, "m/d/yyyy") & "#)"

Duane
Hook'D on Access
MS Access MVP
 
Why not simply this ?
Code:
stLinkCriteria = 
  "(DateCreated BETWEEN (Date()-7) And Date()) OR (InvoiceDate BETWEEN (Date()-7) And Date())"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

Thank you both,

dhookom i have amended as you say however the error still returns.

PHV i get the error 'Date' is not a recognized built-in function name.

This maybe because we are running an SQL Server backend.

Thanks
B
 
OK, hopefully next time you'll explain the whole story ...
 
Sorry for not explaining the whole story... And thanks for your posts:

They are SQL Server DATETIME fields.

Its an ADP

Acutally I made it work by using this code:

stLinkCriteria = "([DateCreated] BETWEEN '" & Format(DateAdd("d", -7, Date), "yyyymmdd") & "' AND '" & Format(Date, "yyyymmdd") & "') OR ([InvoiceDate] BETWEEN '" & Format(DateAdd("d", -7, Date), "yyyymmdd") & "' AND '" & Format(Date, "yyyymmdd") & "')"

Thanks again for your input.

B
 
ADP is a huge factor in providing an answer to your question. PH's solution could be
Code:
stLinkCriteria = 
  "(DateCreated BETWEEN (GetDate()-7) And GetDate()) OR (InvoiceDate BETWEEN (GetDate()-7) And GetDate())"


Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top