By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

Open Report Code Error

100+
P: 114
Hello,
I have a report that I open that pull its data from a form that builds a where string. Opening the report first opens the form, where I enter criteria, and then pulls matching records from a table, opens the report, and closes the form. The code on the report is below.

I used this code on a similar report that also pulled its data from a form (the difference was that that form supplied criteria to an actual query - my new form builds the where string from criteria itself). So, the problem is that I get an error:
Compile error: Sub or Function not defined when I try to open the report and it points to line 16 below (the code to cancel opening the report if the user selects the cancel button on the criteria form). If I comment out this line, the code works fine, opening the report properly. However, if the user selects the cancel button on the criteria form, the report still opens displaying all data.

Any ideas would be most appreciated! Thank you.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Report_Close()
  4.   DoCmd.close acForm, "Survey Form"
  5. End Sub
  6.  
  7. Private Sub Report_Open(cancel As Integer)
  8. ' Set public variable to true to indicate that the report
  9. ' is in the Open event
  10.   bInReportOpenEvent = True
  11.  
  12. ' Open Survey Criteria Dialog
  13.   DoCmd.OpenForm "Survey Form", , , , , acDialog
  14.  
  15. ' Cancel Report if User Clicked the Cancel Button
  16.   If IsLoaded("Survey Form") = False Then cancel = True
  17.  
  18. ' Set public variable to false to indicate that the
  19. ' Open event is completed
  20.   bInReportOpenEvent = False
  21. End Sub
Oct 24 '07 #1
Share this Question
Share on Google+
7 Replies


Rabbit
Expert Mod 10K+
P: 12,327
That's not how you use IsLoaded.

CurrentProject.AllForms("Name").IsLoaded

Also, you can't cancel the On Close event. But you can cancel the Unload event.
Oct 24 '07 #2

100+
P: 114
That's not how use IsLoaded.

CurrentProject.AllForms("Name").IsLoaded

Also, you can't cancel the On Close event. But you can cancel the Unload event.
So to stop the report from generating when the user presses "cancel" on the form...? I'm sorry, just not sure of all the various events at my disposal.
Thanks.
Oct 24 '07 #3

Rabbit
Expert Mod 10K+
P: 12,327
Sorry, didn't realize you were trying to cancel the opening of a report. That part is fine as far as I can tell, you just have to change the IsLoaded part.
Oct 24 '07 #4

100+
P: 114
Sorry, didn't realize you were trying to cancel the opening of a report. That part is fine as far as I can tell, you just have to change the IsLoaded part.
A little confused...to what would I be changing it?
Oct 24 '07 #5

Rabbit
Expert Mod 10K+
P: 12,327
A little confused...to what would I be changing it?
The IsLoaded syntax, you're using it wrong. There's an example in post #2 of how it's supposed to look.
Oct 24 '07 #6

100+
P: 114
The IsLoaded syntax, you're using it wrong. There's an example in post #2 of how it's supposed to look.
Sorry - I got it. Thanks, Rabbit. The report does not generate when the user selects "cancel" from the form now. Thank you!
Expand|Select|Wrap|Line Numbers
  1. ' Cancel Report if User Clicked the Cancel Button
  2.   If CurrentProject.AllForms("Survey Form").IsLoaded = False Then cancel = True
martin
Oct 25 '07 #7

Rabbit
Expert Mod 10K+
P: 12,327
Sorry - I got it. Thanks, Rabbit. The report does not generate when the user selects "cancel" from the form now. Thank you!
Expand|Select|Wrap|Line Numbers
  1. ' Cancel Report if User Clicked the Cancel Button
  2.   If CurrentProject.AllForms("Survey Form").IsLoaded = False Then cancel = True
martin
Not a problem, goodluck.
Oct 25 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.