Access Macros

C

ChrisL7

I am trying to use a macro in Access to highlight expired date entries in the
database. I can do this by calling up a report in a macro and notifying the
user, but I don't want the report to show if there is no detail. Currently, I
can't get the macro to work without calling up the report on screen and, if
there are no expired dates, I get a 'data type mismatch' error message.
Ideally, I would like the user to be unaware of the running macro unless
there are expired dates which need correcting, in which case a visible report
would be satisfactory. Can anyone suggest a way of doing this?
 
C

Chris Reveille

Chris,

I am guessing that you want to cancel the report if there
is no data. You can use the Report's OnNoData event for
this. For example, the following code

'************* Code Start **************
** Put this on the NoData event in report

Private Sub Report_NoData(Cancel As Integer)

MsgBox "No data found! Closing report."

Cancel = True
End Sub

'************* Code End *************

will automatically close the report if there are no
records in the underlying source. However, if you're
opening the report from code behind a form, you need to
handle the error that's generated as a result.

'*********** Code Start ************

Private Sub TestNoData_Click()

On Error Resume Next ' change On error to this - this
statement is all you need
DoCmd.OpenReport "SomeReport", acViewPreview
If Err = 2501 Then Err.Clear

End Sub

'*********** Code End ************

Good Luck

Jim
 
S

Steve Schapel

Chris,

Are you using an OpenReport action in your macro? If so, you can put
this in the Condition column of your macro design...
DCount("*","YourQuery")>0
.... where YourQuery is the name of the query that the report is based
on. That way, the OpenReport action will only happen if there are
expired dates 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