filter form by specific date from text box

johnnychow

Registered User.
Local time
Today, 14:08
Joined
Jul 28, 2011
Messages
20
Hi: Please tell me what's wrong on the following, the beging date is ok but the end date is error. If put actual date instead, the statement will be ok. why?

Dim LSQL As String

LSQL = "Select * from [Offering] where [Offering].[OfferDate]" & _
"between #" & Format(Me("TxtBeginDate").Value, "mm/dd/yyyy")" & _
"& "# And #" & Format(Me("TxtEndDate").Value, "mm/dd/yyyy") & "#"

[Form_Statement Subform].RecordSource = LSQL

or

LSQL = "select * from [Offering] where [Offering].[OfferDate] between" & _
"#" & Me.TxtBeginDate & "# and #" & Me.TxtEndDate & "#"
 
Why change the record source? Just use the Filter property:

Code:
Dim strWhere As String
 
strWhere = "[OfferDate] Between " & _
"Format(Me.TxtBeginDate, "\#mm\/dd\/yyyy\#)" & _
" And " & Format(Me.TxtEndDate, "\#mm\/dd\/yyyy\#)"
 
 
Me.Filter = strWhere
Me.FilterOn = True

Then to set it back just use
Code:
Me.Filter = vbNullString
Me.FilterOn = False

by the way the \ part in the format tells it to use the explicit character, which can help if regional settings are messing things up.
 
Why change the record source? Just use the Filter property:

Code:
Dim strWhere As String
 
strWhere = "[OfferDate] Between " & _
"Format(Me.TxtBeginDate, "\#mm\/dd\/yyyy\#)" & _
" And " & Format(Me.TxtEndDate, "\#mm\/dd\/yyyy\#)"
 
 
Me.Filter = strWhere
Me.FilterOn = True

Then to set it back just use
Code:
Me.Filter = vbNullString
Me.FilterOn = False

by the way the \ part in the format tells it to use the explicit character, which can help if regional settings are messing things up.


Hi! has a syntax error, can you help me most.
 
Sorry, got a few things out of place, it should be:
Code:
strWhere = "[OfferDate] Between [COLOR=red][B]" &[/B][/COLOR] Format(Me.TxtBeginDate, "\#mm\/dd\/yyyy\#[B][COLOR=red]")[/COLOR][/B] & _
" And " & Format(Me.TxtEndDate, "\#mm\/dd\/yyyy\#[B][COLOR=red]")[/COLOR][/B]
 

Users who are viewing this thread

Back
Top Bottom