The form is Master Data Form1. I'm using the event procedure on "before
update".
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err
' Set bound controls to system date and time.
DateModified = Date
TimeModified = Time()
BeforeUpdate_End:
Exit Sub
BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occurred"
Resume BeforeUpdate_End
End Sub
Private Sub Form_Open(Cancel As Integer)
dtmIncludeDate = DateAdd("d", -7, Date)
strWhere = "[Date Modified] <= #" & dtmIncludeDate & "#"
DoCmd.OpenForm "Master Data Form1", , , strWhere
End Sub
I'm still not getting any data. What am I doing wrong?
Klatuu said:
First, Katie, I made an error. the <= should be >=. The original code would
have shown only records over 7 days old.
What form is the Open event from?
You are not returning any records. If you get one empty line, that is a new
record.
Note that [Date Modified] should be a field in the form's recordset.
Katie said:
This is the Event Procedure I entered on the "On Open" field:
Private Sub Form_Open(Cancel As Integer)
dtmIncludeDate = DateAdd("d", -7, Date)
strWhere = "[Date Modified] <= #" & dtmIncludeDate & "#"
DoCmd.OpenForm "Master Data Form1", , , strWhere
End Sub
It pulls one record, which is correct, but it doesn't pull any of the data
with the record. What am I doing wrong?
:
Use the Where argument of the OpenForm method where you open the form to set
up the filtering criteria:
dtmIncludeDate = DateAdd("d", -7, Date)
strWhere = "[Date Modified] <= #" & dtmIncludeDate & "#"
Docmd.OpenForm "MyFormName", , ,strWhere
:
I've set up a form with the "Date Modified" field on it. I would like the
user to be able to filter the records by those that have been modified within
the past 7 days.
How do I accomplish this?
Thank you.