Sorting by Dates less than

J

justlearnin

I have a form set up to pick the date to run report as anything lower than
date selected. How would I code thos in vb?
 
G

Graham Mandeno

You need to build a filter string and pass it to the report via the
"WhereCondition" in OpenReport.

The string needs to be in the form:
"[name of date field] < #mm/dd/yyyy#"

For example:
"[ExpiryDate] < #08/17/2005#"

Assuming your date is in a textbox named "txtPickDate", and you have a
command button to open the report, the code behind the button's click event
should look something like this:

Dim sFilter as string
sFilter = "[ExpiryDate] < " & Format( txtPickDate, "\#mm\/dd\/yyyy" )
DoCmd.Openreport "Your report name", WhereCondition:=sFilter
 
O

Ofer

If you are trying to open a report based on a field in the form, then create
a button, on the on click event enter the code

docmd.OpenReport "reportName",,,"[DateFieldName] < #" & Me.DateTextFieldName
& "#"
 
J

justlearnin

docmd.OpenReport "ExpiredMVR",,,"[LastMVR] < #" & Me.PastDate & "#"
This didnt work
ExpiredMVR is the report, LastMVR is date in table, Me.PastDate is the date
to search for.
I want it to pull any dates before PastDate

Ofer said:
If you are trying to open a report based on a field in the form, then create
a button, on the on click event enter the code

docmd.OpenReport "reportName",,,"[DateFieldName] < #" & Me.DateTextFieldName
& "#"

--
In God We Trust - Everything Else We Test


justlearnin said:
I have a form set up to pick the date to run report as anything lower than
date selected. How would I code thos in vb?
 
O

Ofer

When you run the report, does it display all the records, it shouldn't have
any filter in it.

--
In God We Trust - Everything Else We Test


justlearnin said:
docmd.OpenReport "ExpiredMVR",,,"[LastMVR] < #" & Me.PastDate & "#"
This didnt work
ExpiredMVR is the report, LastMVR is date in table, Me.PastDate is the date
to search for.
I want it to pull any dates before PastDate

Ofer said:
If you are trying to open a report based on a field in the form, then create
a button, on the on click event enter the code

docmd.OpenReport "reportName",,,"[DateFieldName] < #" & Me.DateTextFieldName
& "#"

--
In God We Trust - Everything Else We Test


justlearnin said:
I have a form set up to pick the date to run report as anything lower than
date selected. How would I code thos in vb?
 
J

justlearnin

Yes, The report that I was running should leave out anything after 8/16/2002,
but all are there, no filter

Ofer said:
When you run the report, does it display all the records, it shouldn't have
any filter in it.

--
In God We Trust - Everything Else We Test


justlearnin said:
docmd.OpenReport "ExpiredMVR",,,"[LastMVR] < #" & Me.PastDate & "#"
This didnt work
ExpiredMVR is the report, LastMVR is date in table, Me.PastDate is the date
to search for.
I want it to pull any dates before PastDate

Ofer said:
If you are trying to open a report based on a field in the form, then create
a button, on the on click event enter the code

docmd.OpenReport "reportName",,,"[DateFieldName] < #" & Me.DateTextFieldName
& "#"

--
In God We Trust - Everything Else We Test


:

I have a form set up to pick the date to run report as anything lower than
date selected. How would I code thos in vb?
 
J

justlearnin

This is what I have right now

Dim stDocName As String

stDocName = "rptExpiredMVR"
DoCmd.OpenReport "rptExpiredMVR", , , "[LastMVR] < #Me.PastDate[mm/dd/yyyy]#"

Ofer said:
When you run the report, does it display all the records, it shouldn't have
any filter in it.

--
In God We Trust - Everything Else We Test


justlearnin said:
docmd.OpenReport "ExpiredMVR",,,"[LastMVR] < #" & Me.PastDate & "#"
This didnt work
ExpiredMVR is the report, LastMVR is date in table, Me.PastDate is the date
to search for.
I want it to pull any dates before PastDate

Ofer said:
If you are trying to open a report based on a field in the form, then create
a button, on the on click event enter the code

docmd.OpenReport "reportName",,,"[DateFieldName] < #" & Me.DateTextFieldName
& "#"

--
In God We Trust - Everything Else We Test


:

I have a form set up to pick the date to run report as anything lower than
date selected. How would I code thos in vb?
 
O

Ofer

Try this

Dim stDocName As String

stDocName = "rptExpiredMVR"
DoCmd.OpenReport stDocName , , , "[LastMVR] < #" &
Format(Me.PastDate,[mm/dd/yyyy]) & "#"


--
In God We Trust - Everything Else We Test


justlearnin said:
This is what I have right now

Dim stDocName As String

stDocName = "rptExpiredMVR"
DoCmd.OpenReport "rptExpiredMVR", , , "[LastMVR] < #Me.PastDate[mm/dd/yyyy]#"

Ofer said:
When you run the report, does it display all the records, it shouldn't have
any filter in it.

--
In God We Trust - Everything Else We Test


justlearnin said:
docmd.OpenReport "ExpiredMVR",,,"[LastMVR] < #" & Me.PastDate & "#"
This didnt work
ExpiredMVR is the report, LastMVR is date in table, Me.PastDate is the date
to search for.
I want it to pull any dates before PastDate

:

If you are trying to open a report based on a field in the form, then create
a button, on the on click event enter the code

docmd.OpenReport "reportName",,,"[DateFieldName] < #" & Me.DateTextFieldName
& "#"

--
In God We Trust - Everything Else We Test


:

I have a form set up to pick the date to run report as anything lower than
date selected. How would I code thos in vb?
 
J

justlearnin

I'm not understanding why it isnt working, I got all of the records again

Ofer said:
Try this

Dim stDocName As String

stDocName = "rptExpiredMVR"
DoCmd.OpenReport stDocName , , , "[LastMVR] < #" &
Format(Me.PastDate,[mm/dd/yyyy]) & "#"


--
In God We Trust - Everything Else We Test


justlearnin said:
This is what I have right now

Dim stDocName As String

stDocName = "rptExpiredMVR"
DoCmd.OpenReport "rptExpiredMVR", , , "[LastMVR] < #Me.PastDate[mm/dd/yyyy]#"

Ofer said:
When you run the report, does it display all the records, it shouldn't have
any filter in it.

--
In God We Trust - Everything Else We Test


:

docmd.OpenReport "ExpiredMVR",,,"[LastMVR] < #" & Me.PastDate & "#"
This didnt work
ExpiredMVR is the report, LastMVR is date in table, Me.PastDate is the date
to search for.
I want it to pull any dates before PastDate

:

If you are trying to open a report based on a field in the form, then create
a button, on the on click event enter the code

docmd.OpenReport "reportName",,,"[DateFieldName] < #" & Me.DateTextFieldName
& "#"

--
In God We Trust - Everything Else We Test


:

I have a form set up to pick the date to run report as anything lower than
date selected. How would I code thos in vb?
 
O

Ofer

The LastMVR field is a date/time type?
if not use that, try it anyway

stDocName = "rptExpiredMVR"
DoCmd.OpenReport stDocName , , , "cvdate(format([LastMVR],"mm/dd/yyyy")) <
#" &
Format(Me.PastDate,[mm/dd/yyyy]) & "#"

--
In God We Trust - Everything Else We Test


justlearnin said:
I'm not understanding why it isnt working, I got all of the records again

Ofer said:
Try this

Dim stDocName As String

stDocName = "rptExpiredMVR"
DoCmd.OpenReport stDocName , , , "[LastMVR] < #" &
Format(Me.PastDate,[mm/dd/yyyy]) & "#"


--
In God We Trust - Everything Else We Test


justlearnin said:
This is what I have right now

Dim stDocName As String

stDocName = "rptExpiredMVR"
DoCmd.OpenReport "rptExpiredMVR", , , "[LastMVR] < #Me.PastDate[mm/dd/yyyy]#"

:

When you run the report, does it display all the records, it shouldn't have
any filter in it.

--
In God We Trust - Everything Else We Test


:

docmd.OpenReport "ExpiredMVR",,,"[LastMVR] < #" & Me.PastDate & "#"
This didnt work
ExpiredMVR is the report, LastMVR is date in table, Me.PastDate is the date
to search for.
I want it to pull any dates before PastDate

:

If you are trying to open a report based on a field in the form, then create
a button, on the on click event enter the code

docmd.OpenReport "reportName",,,"[DateFieldName] < #" & Me.DateTextFieldName
& "#"

--
In God We Trust - Everything Else We Test


:

I have a form set up to pick the date to run report as anything lower than
date selected. How would I code thos in vb?
 
J

justlearnin

That didnt work either, but Im out of time for today, Thanks for all of your
help.

Ofer said:
The LastMVR field is a date/time type?
if not use that, try it anyway

stDocName = "rptExpiredMVR"
DoCmd.OpenReport stDocName , , , "cvdate(format([LastMVR],"mm/dd/yyyy")) <
#" &
Format(Me.PastDate,[mm/dd/yyyy]) & "#"

--
In God We Trust - Everything Else We Test


justlearnin said:
I'm not understanding why it isnt working, I got all of the records again

Ofer said:
Try this

Dim stDocName As String

stDocName = "rptExpiredMVR"
DoCmd.OpenReport stDocName , , , "[LastMVR] < #" &
Format(Me.PastDate,[mm/dd/yyyy]) & "#"


--
In God We Trust - Everything Else We Test


:

This is what I have right now

Dim stDocName As String

stDocName = "rptExpiredMVR"
DoCmd.OpenReport "rptExpiredMVR", , , "[LastMVR] < #Me.PastDate[mm/dd/yyyy]#"

:

When you run the report, does it display all the records, it shouldn't have
any filter in it.

--
In God We Trust - Everything Else We Test


:

docmd.OpenReport "ExpiredMVR",,,"[LastMVR] < #" & Me.PastDate & "#"
This didnt work
ExpiredMVR is the report, LastMVR is date in table, Me.PastDate is the date
to search for.
I want it to pull any dates before PastDate

:

If you are trying to open a report based on a field in the form, then create
a button, on the on click event enter the code

docmd.OpenReport "reportName",,,"[DateFieldName] < #" & Me.DateTextFieldName
& "#"

--
In God We Trust - Everything Else We Test


:

I have a form set up to pick the date to run report as anything lower than
date selected. How would I code thos in vb?
 
Top