Form Filter Question

anunat

New member
Local time
Today, 17:37
Joined
Jun 25, 2012
Messages
6
I have a form that has four combo boxes

FromMonth, FromYear, ToMonth, ToYear

I have a dropdown list for each of them. I am doing it this way, because the data comes in once every month. So only month and year are relevant.

I use the following code to convert them to date format:

fromdate = DateValue(Me.Frommonth & "/" & "01/" & Me.Fromyear)

todate = DateValue(Me.Tomonth & "/" & "01/" & Me.Toyear)

My table has a date field. I would like to run a query from the above form for all dates between fromdate and todate.

How do I do this?​
 
Use this instead:

1. Use a form to display the query (so bind the query to the form). It can be set to Datasheet view if you want so it looks like the query is opening by itself, but with the form you can pass the values to the form when opening to limit it as you wish. Also, this method doesn't make you put the criteria into the query so then it is reusable in other situations.

2. code:
Code:
' 
 
DoCmd.OpenForm "FormNameHere", acViewNormal, , "[DateFieldName] Between " & DateSerial(Me.FromYear, Me.Frommonth, 1)" & " And  " & DateSerial(Me.ToYear, Me.ToMonth, 1)
 
'
 
Last edited:

Users who are viewing this thread

Back
Top Bottom