Access crashes when I apply a filter to open a Macro.

  • Thread starter Frank The Novice
  • Start date
F

Frank The Novice

Hello Folks,

I have a table that has several events per day, and I want to generate a
report of the events that were done on a specific day.

My problem is Access keeps crashing when I try to open a report with the
following Load event:

Private Sub Report_Load()
DoCmd.ApplyFilter , "DoF = #01/01/2009#"
End Sub

I can get around this by just applying the filter in the report data block.
However, I have a command button that will take me to the first record in the
query. The code I use is:

Private Sub Command19_Click()
Dim TDate As Date
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Sector Record Query")
rst.MoveFirst
TDate = rst![DoF]
DoCmd.ApplyFilter , "DoF = #" & TDate & "#"
rst.Close
End Sub

But every time I click the button, Access shuts down and restarts, but never
tells me what I did wrong.

Any suggestions?

Frank
 
A

Allen Browne

Try setting the report's Filter property in its Open event:

Private Sub Report_Open(Cancel As Integer)
Me.Filter = "[DoF] = #01/01/2009#"
Me.FilterOn = True
End Sub

Alternatively, open the report from elsewhere (e.g. a form button), so you
can use its WhereCondition:

strWhere = "[DoF] = #01/01/2009#"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere

This assumes that:
a) there is a control named DoF on the report;
b) this controls is bound to a field named DoF;
c) this field is a date/time field.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

message
news:[email protected]...
 
F

Frank The Novice

Thanks, Allen. Everything seems to be working like I want now.

I appreciate your help.

Frank

Allen Browne said:
Try setting the report's Filter property in its Open event:

Private Sub Report_Open(Cancel As Integer)
Me.Filter = "[DoF] = #01/01/2009#"
Me.FilterOn = True
End Sub

Alternatively, open the report from elsewhere (e.g. a form button), so you
can use its WhereCondition:

strWhere = "[DoF] = #01/01/2009#"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere

This assumes that:
a) there is a control named DoF on the report;
b) this controls is bound to a field named DoF;
c) this field is a date/time field.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

message
Hello Folks,

I have a table that has several events per day, and I want to generate a
report of the events that were done on a specific day.

My problem is Access keeps crashing when I try to open a report with the
following Load event:

Private Sub Report_Load()
DoCmd.ApplyFilter , "DoF = #01/01/2009#"
End Sub

I can get around this by just applying the filter in the report data
block.
However, I have a command button that will take me to the first record in
the
query. The code I use is:

Private Sub Command19_Click()
Dim TDate As Date
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Sector Record Query")
rst.MoveFirst
TDate = rst![DoF]
DoCmd.ApplyFilter , "DoF = #" & TDate & "#"
rst.Close
End Sub

But every time I click the button, Access shuts down and restarts, but
never
tells me what I did wrong.
 

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