Form filter for date range

G

Guest

I am a true beginner and there maybe a simple solution for my problem. I am
running a form using a query and trying to include sort of a filter on the
open event but in the "Where", but it appears that my query is running
without reviewing checking the "Where". Please see my code below:


Private Sub Form_Open(Cancel As Integer)

DoCmd.OpenForm "Form Date Range", , , "Me.[Work Completed] >= &
[Forms]![Form Date Range]![Beginning Entry Date] And Me.[Work Completed]<=
&[Forms]![Form Date Range]![Ending Entry Date]", , acDialog, "Duplicates in
Associates Productivity"

End Sub


Is there a simple solution?
 
W

Wayne Morgan

First, I just want to double check what you're trying to do. You are running
this code on a form (not Form Date Range) and you want to open Form Date
Range from the form that this code is running on. The dates you want to use
for filtering Form Date Range are on the form that this code is running on.

Assuming the above to be correct, you need to make a few syntax changes to
your code. To incorporate values from the current form, you either need to
take them out of the quote marks so VBA will interpret them (items within
the quotes are simply passed as-is) to their values or you need to pass them
in the filter in a format that Form Date Range will be able to find them on
the current form. Also, just as strings are delimited using quotes, dates
are delimited using #'s. If your system doesn't use US date format, you may
also have to format the date value to US format for the filter to work
properly.

It appears that you are trying to pass the item using the second method
above (formatting it so the receiving form will know where to look to get
the value). However, the form you are looking back to ([Forms]![Form Date
Range]![Beginning Entry Date]) is the same form you are opening (Form Date
Range). Your "Duplicates in Associates Productivity" is being passed as the
OpenArgs argument. This value can then be detected in the form being opened
to do something that you want to do, such as change the Caption of the form.
Is this what you intend to use this for?

Example:
If Me.OpenArgs<>"" Then Me.Caption = Me.OpenArgs

To help further, we'll need a better explanation of what you're trying to
do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top