Using Combo Box to Select Date Range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a set of records that I would like to filter with a range of dates

I would like to select those dates via a form. How do I use the combo boxes, CboStartDate & cboEndDate to select the records in that range

O

If you have a better idea, let me know

Thanks As Always
RIP
 
FIELD: YourDateField
CRITERIA: Between FORMS![YourFormName]!cboStartDate and Forms![YourFormName]!cboEndDate

The form must be open and the comboboxes must have valid dates in them.
 
Set the Filter of your form to a statement that looks like the WHERE clause
from a query. The dates must be in the American format.

Dim strWhere As String
Dim conJetDate ="\#mm\/dd\/yyyy\#"
If IsNull(Me.cboStartDate) Or IsNull(Me.cboEndDate) Then
MsgBox "Both dates needed"
Else
strWhere = "[MyDate] Between " & _
Format(Me.cboStartDate, conJetDate) & " And " & _
Format(Me.cboEndDate, conJetDate)
Me.Filter = strWhere
Me.FilterOn = True
End If

Notes:
1. cboStartDate and cboEndDate are probably unbound. To tell Access that
only valid dates are acceptable, set their Format propety to "Short Date" or
similar.

2. Code assumes there is no time component in the field.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Ripper said:
I have a set of records that I would like to filter with a range of dates.

I would like to select those dates via a form. How do I use the combo
boxes, CboStartDate & cboEndDate to select the records in that range?
 
Hi - Ok if you make a blank form then add to it two combo
boxes with and make sure their names are CboStartDate &
CboEndDate you can then use these values as you would use
a parameter value in a query to pull out records between
the two dates. You need to make a query with your records
in - if you have just one date field:

In the criteria row for the date field type the criteria as

Between (startdate) and (enddate)

only you have to reference the CboStartDate and CboEndDate
boxes on the form so it looks like this:

Between ([Forms]![NameofForm]![CboStartDate]) and ([Forms]!
[NameofForm]![CboStartDate])

This should work as long as you have the form open when
you run the query - so usually its easy just to make a
command button that opens the query on the form - there is
a wizard once you draw the button

If you have 2 fields - startdate and enddate - just
reference the appropriate combo box in the criteria of
each field.

Hope this makes sense -

Natalie

-----Original Message-----
I have a set of records that I would like to filter with a range of dates.

I would like to select those dates via a form. How do I
use the combo boxes, CboStartDate & cboEndDate to select
the records in that range?
 
Can Some one please help me with this;

Instead of Combo boxes I have Calendars cal1 and cal2 to select date ranges;
In the query criteria I'm using the expression Between [Forms]![FrmReconall]![cal1] And [Forms]![FrmReconall]![cal2]

But the problem is this works fine and displays all records when the range selected is say from 6/1/2004 to 6/9/2004. But when I select the dates from 6/1/2004 to 6/10/2004 it displays only the first and last records. I'm really not able to figure the problem here.

Thanks in advance.


Natalie said:
Hi - Ok if you make a blank form then add to it two combo
boxes with and make sure their names are CboStartDate &
CboEndDate you can then use these values as you would use
a parameter value in a query to pull out records between
the two dates. You need to make a query with your records
in - if you have just one date field:

In the criteria row for the date field type the criteria as

Between (startdate) and (enddate)

only you have to reference the CboStartDate and CboEndDate
boxes on the form so it looks like this:

Between ([Forms]![NameofForm]![CboStartDate]) and ([Forms]!
[NameofForm]![CboStartDate])

This should work as long as you have the form open when
you run the query - so usually its easy just to make a
command button that opens the query on the form - there is
a wizard once you draw the button

If you have 2 fields - startdate and enddate - just
reference the appropriate combo box in the criteria of
each field.

Hope this makes sense -

Natalie

-----Original Message-----
I have a set of records that I would like to filter with a range of dates.

I would like to select those dates via a form. How do I
use the combo boxes, CboStartDate & cboEndDate to select
the records in that range?
OR

If you have a better idea, let me know.

Thanks As Always,
RIP
.
 
Hi Dale,

Do you by any chance know what installs this ocx?
I don't have it on my machine so do you know where I'd get it? [legitimately!]

Cheers
Matt
 
Hi Dale,

Do you by any chance know what installs this ocx?
I don't have it on my machine so do you know where I'd get it? [legitimately!]

Cheers
Matt
 
Back
Top