Hello:
I'm really scratching my head on this one.
I've been rewriting some code for my database but something that seemed to work fine before now apparently doesn't, or at least, not as I'd expect.
Here's what I have:
I have a form that populates certain fields in a query that is used as the source for the report.
My form:
1. Grabs the entered values form the form
2. Selects a query appropriate for those values
3. Opens the report in design mode to set the Report's control source for that query
4. Opens the report in acPrintPreview.
When there is data for the report it Previews fine.
Now here's where I'm struggling:
I have a simple piece of code on OnNoData:
That's it.
I use this variable as part of the Report's OnActivate Event to test for whether or not there are no values in the report when it first opens..
(cribbing from OnActivate code, this is at the top of the code before anything else is done..)
My problem is varNoData fires and gets set to 1 when there are no report values, so that works, but it does not get passed to OnActivate, so I get a 2501 or other error!
In the past, I thought this worked! I can't be sure, which is what is so frustrating - am I missing something?
I've tried removing this approach and code completely and tried the FAQ 703-1594 that deals exclusively with this issue - all I want is to print out a Message Box and then close the report, is this so hard?
When I use the FAQ code, I see the "No Data" message, so that works, but despite including the error traps exactly as the code instructs, I STILL get Error 2501 after the No Data Message appears!
errr...HELP?
Thanks,
marcus101
Access/SQL/XML Developer
Ottawa, Canada
I'm really scratching my head on this one.
I've been rewriting some code for my database but something that seemed to work fine before now apparently doesn't, or at least, not as I'd expect.
Here's what I have:
I have a form that populates certain fields in a query that is used as the source for the report.
My form:
1. Grabs the entered values form the form
2. Selects a query appropriate for those values
3. Opens the report in design mode to set the Report's control source for that query
4. Opens the report in acPrintPreview.
When there is data for the report it Previews fine.
Now here's where I'm struggling:
I have a simple piece of code on OnNoData:
Code:
varNoData = 1
That's it.
I use this variable as part of the Report's OnActivate Event to test for whether or not there are no values in the report when it first opens..
(cribbing from OnActivate code, this is at the top of the code before anything else is done..)
Code:
If varNoData = 1 Then
MsgBox "No items in the report."
DoCmd.Close acReport, "ReportName"
Else
' do nothing..
End If
My problem is varNoData fires and gets set to 1 when there are no report values, so that works, but it does not get passed to OnActivate, so I get a 2501 or other error!
In the past, I thought this worked! I can't be sure, which is what is so frustrating - am I missing something?
I've tried removing this approach and code completely and tried the FAQ 703-1594 that deals exclusively with this issue - all I want is to print out a Message Box and then close the report, is this so hard?
When I use the FAQ code, I see the "No Data" message, so that works, but despite including the error traps exactly as the code instructs, I STILL get Error 2501 after the No Data Message appears!
errr...HELP?
Thanks,
marcus101
Access/SQL/XML Developer
Ottawa, Canada