String Syntax

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

String Syntax

Post by burrina »

Dte1 = >= Me!frmMainMenu.StartDate
Not sure if this correct or not! I'm trying to eliminate using Between start and end dates since it is not reliable.
Not sure if I needed to add to the end of the statement or not.

User avatar
HansV
Administrator
Posts: 78472
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: String Syntax

Post by HansV »

The first = is superfluous:

Dte1 >= Me!frmMainMenu.StartDate
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: String Syntax

Post by burrina »

Code: Select all

Dim Dte1 As String 'Loads with frmMainMenu
Dim Dte2 As String


Dte1 = >= Me!frmMainMenu.StartDate
Dte2 = <= Me!frmMainMenu.EndDat
Maybe this will help. I dont want to have to enter a whole string into the grid, just Between Dte1 and Dte2
Between by itself is no good. Like Between start date and enddate since Access sees midnight as the cutoff you wont get a correct result.
Hence the need for a better way! Dteq=1 and Dte2 works fine thee way it was without >= or <=

User avatar
HansV
Administrator
Posts: 78472
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: String Syntax

Post by HansV »

Dte1 = >= Me!frmMainMenu.StartDate
Dte2 = <= Me!frmMainMenu.EndDat

makes no sense in VBA. Can you explain what you want to do?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: String Syntax

Post by burrina »

I set the date variable when the frmMainMenu loads. It is and has been used in my databases. I then can enter into a qry or frm Between Dte1 and Dte2 for the date criteria. However, now I am using the time part of the date so I need to make sure that the syntax is correct.
I can no longer simply say Between start and end date in the qy or frm.

Since Dte1 and Dte2 are variables, I can use them. I select a startdate via a popup calendar on the form and it inputs it into the StartDate field
Same goes for EndDat, I can then filter my forms, reports or use as syntax in my queries.
I dont want to hard code anything since the dates change often.

User avatar
HansV
Administrator
Posts: 78472
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: String Syntax

Post by HansV »

Can you post the part of the code where you use Dte1 and Dte2?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: String Syntax

Post by burrina »

WkEndDate ' is a date field
Between [Dte1] and [Dte2]

User avatar
HansV
Administrator
Posts: 78472
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: String Syntax

Post by HansV »

That doesn't help. Please try to provide sufficient information.
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: String Syntax

Post by burrina »

If I enter 3/2/2021 as the StartDate and 3/15/2021 as the EndDat and then run my report, query I need to make sure that it is allowing for the Date/Time since Access cuts off at midnight, I could use Between Start and EndDate in the query and get the wrong result.
If I use my Dte1 and Dte2 I want to make sure that does not happen. I am looking for the correct syntax for the StartDate and EndDat fields to pass into my qry,frm.rpt !
In other words, I need to adjust the 3/2/2021 (StartDate) & (EndDat) to #03/02/2021# so it wont cause any errors.

User avatar
HansV
Administrator
Posts: 78472
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: String Syntax

Post by HansV »

You'll need

>=Me!frmMainMenu.StartDate

and

<Me!frmMainMenu.EndDat+1
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: String Syntax

Post by burrina »

I was experimenting with this, am I off? I think I would need to declare them individually?

Dim strDateFilter as String
strDateFilter = Between #" & Dte1 & "# And #" & Dte2 & "# "

User avatar
HansV
Administrator
Posts: 78472
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: String Syntax

Post by HansV »

You'll need something like

"[DateField]>=#" & Dte1 & "# And [DateField]<#" & Dte2 + 1 & "#"
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: String Syntax

Post by burrina »

Many Thanks, sorry for the long way around.