Re: Filter form on load (show this years records only)

A

Allen Browne

Use the form's Open event procedure to apply a filter.

This kind of thing:

Private Sub Form_Open(Cancel As Integer)
Me.Filter = "[DATE] >= #" & Year(Date) & "/1/1#"
Me.FilterOn = True
End Sub

Note that DATE is a reserved word, so not a good name for a field. In some
contexts, Access confuses it with the system date, and so does not yield the
results you expect. Consider renaming the field to InvoiceDate or something.
 
D

Douglas J. Steele

While the field in your table shouldn't be named Date (and I see you changed
it), you need to call the Date function when setting the function:

Me.Filter = "[MaintDATE]>= #" & Year(Date) & "/1/1#"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Russ via AccessMonster.com said:
Allen, thanks for the help, but not having luck with it, it gives an error
has no value.

Private Sub Form_Open(Cancel As Integer)

Me.Filter = "[MaintDATE]>= #" & Year(MaintDate) & "/1/1#"
Me.FilterOn = True

End Sub

Allen said:
Use the form's Open event procedure to apply a filter.

This kind of thing:

Private Sub Form_Open(Cancel As Integer)
Me.Filter = "[DATE] >= #" & Year(Date) & "/1/1#"
Me.FilterOn = True
End Sub

Note that DATE is a reserved word, so not a good name for a field. In some
contexts, Access confuses it with the system date, and so does not yield
the
results you expect. Consider renaming the field to InvoiceDate or
something.
[quoted text clipped - 5 lines]
see
all records.
 
D

Douglas J. Steele

Does the error say it can't find Date or that it can't find MaintDATE?

If it's complaining about MaintDATE, are you sure that that's what you named
the field in your table?

If it's complaining about Date, check whether the Date function works for
you. Go to the Immediate Window (Ctrl-G), type

?Date()

(complete with the question mark), then hit Enter. Do you get a date, or an
error?

If you get an error, there are two common reasons.

The first is that you've used Date somewhere else in your database: a field
in a table, a control on a form, or something like that. Date is a reserved
word, and should never be used in anything you created in the database. Find
that usage, and correct it.

The other possibility is that your references are messed up.

References problems can be caused by differences in either the location or
file version of certain files between the machine where the application was
developed, and where it's being run (or the file missing completely from the
target machine). Such differences are common when new software is installed.

On the machine(s) where it's not working, go into the VB Editor and select
Tools | References from the menu bar. Examine all of the selected
references.

If any of the selected references have "MISSING:" in front of them, unselect
them, and back out of the dialog. If you really need the reference(s) you
just unselected (you can tell by doing a Compile), go back in and reselect
them.

If none have "MISSING:", select an additional reference at random, back out
of the dialog, then go back in and unselect the reference you just added. If
that doesn't solve the problem, try to unselect as many of the selected
references as you can (Access may not let you unselect them all), back out
of the dialog, then go back in and reselect the references you just
unselected. (NOTE: write down what the references are before you delete
them, because they'll be in a different order when you go back in)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Russ via AccessMonster.com said:
Thanks Douglas..

Ok, changed it back to date but, I get run time error saying can not find
field date.
Whatelse am I missing?

Me.Filter = "[MaintDATE]>= #" & Year(Date) & "/1/1#"
While the field in your table shouldn't be named Date (and I see you
changed
it), you need to call the Date function when setting the function:

Me.Filter = "[MaintDATE]>= #" & Year(Date) & "/1/1#"
Allen, thanks for the help, but not having luck with it, it gives an
error
has no value.
[quoted text clipped - 26 lines]
see
all records.
 

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