Limit Records Opened

F

Frank

I have a form that opens all of the past records. I only want to open the
past 100 days of records. How can I set this?

Thank you

Frank
 
D

Douglas J. Steele

Presumably you're using the OpenForm command to open your form, something
like:

DoCmd.OpenForm "NameOfForm", acNormal

You need to change that to

DoCmd.OpenForm "NameOfForm", acNormal, , "NameOfDateField >= " & _
Format(DateAdd("d", -100, Date()), "\#yyyy\-mm\-dd\#")

Replace NameOfForm and NameOfDateField with the appropriate names.
 
F

Frank

Douglas,

I have a macro AutoExec where I Maximize the form. I just added the
OpenForm and wrote in the following: [NameOfForm]![NameOfField] >=Date()-100

Thank you for suggesting OpenForm, does this look okay? It is working
 
D

Douglas J. Steele

I never use macros (other than AutoKeys), so I can't really comment.

If it works, I'd have to assume it's okay.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Frank said:
Douglas,

I have a macro AutoExec where I Maximize the form. I just added the
OpenForm and wrote in the following: [NameOfForm]![NameOfField]
=Date()-100

Thank you for suggesting OpenForm, does this look okay? It is working

Douglas J. Steele said:
Presumably you're using the OpenForm command to open your form, something
like:

DoCmd.OpenForm "NameOfForm", acNormal

You need to change that to

DoCmd.OpenForm "NameOfForm", acNormal, , "NameOfDateField >= " & _
Format(DateAdd("d", -100, Date()), "\#yyyy\-mm\-dd\#")

Replace NameOfForm and NameOfDateField with the appropriate names.
 
Top