Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code does not advance to the next line

Status
Not open for further replies.

blln

Technical User
Jul 14, 2002
13
US
I have a problem with a module I wrote. At a specified set time, the code was supposed to print 2 differet reports. Sometimes one of the report doesn't have any data so it is suppose to skip that report and just print the other report (I set Cancel = true in the NoData event for both of those reports). Sometimes there are no data in both reports so the code is suppose to skip both reports and go to the next line of code, which is to call a function to do certain things.

My code, however, doesn't do that. I thought I did everything right but I couldn't figure out why the module seems to stop advancing to the next line of code if one of the reports doesn't have data. Here is part of my code:

MyTime = #1:00:00 AM# ' Assign a time.

If ((MyTime <> Time) And (Flag = True)) Then
Flag = False
End If


If ((MyTime = Time) And (Flag = False)) Then
DoCmd.OpenReport &quot;MonthlyBillReport&quot;, acNormal
DoCmd.OpenReport &quot;MonthlyBillReport_Reprint&quot;, acNormal

'Call the function named NewInvoices
NewInvoices

Flag = True
End If

If I comment out the two DoCmd lines then the module successfully call the function NewInvoices. If I leave the two DoCmd lines as is, and if the first report (MonthlyBillReport) has no data then the code terminates even if the second report (MonthlyBillReport_Reprint) has data, and it does not call the NewInvoices function either.
If the first report has data and the second report doesn't have data, then it only print the first report and terminate without calling the NewInvoices function. Only when both reports have data to print does it call the NewInvoices function.

Please take a look at my code and tell me why it is behaving so and how I can fix it so that the code advance to the next line even if one or both reports have not data to print.

Any help is appreciated. thank you.
 
Do you have any error handling in your code?

When a report is cancelled, Error 2501 is raised. You could use On Error Resume Next if you want to ignore this and move onto the next line. Alternatively your error handler could check for Err=2501 and then Resume Next.

I'm not sure what else could cause the problem.

Hope this helps.


 
Hello ITMannie,

Thank you for the suggestion. I placed in the code the 2501 error handling code and it works! The lines of code that follow the print report lines do get call. However, now it shows up the message box &quot;No current record&quot;. Do you know how to get rid of it? Besides that annyoing message box, everything is working as it should be. Thank you so much.
 
Let me clear up the above message I'd just sent.

If the first report has data then everything is working perfectly. If only the second report has data then everything is still working perfectly except the message box &quot;No current record&quot; pops up. The important thing is, in both of those cases, the function named NewInvoices do get call.

Thank you again ITMannie for your input. If you could also help me get rid of the message box that would be great.
 
Reports have an onNoData event, or something like that. If you play around with that you may be able to eliminate the message box.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access databases since 1995.
 
Where is the &quot;No Current Record&quot; coming from? The report or the calling procedure.

All I would have for this is:

1. The line of code &quot;Cancel = True&quot; in the report's NoData event (you've got this) - no messages, just the one line of code.

2. In the calling procedure I would have the following error handler

'==================================
On Error Goto ReportErr

...enter all your program code here


Exit Sub
ReportErr:
If Err=2501 then
'Don't display a message just resume at the next line
Resume Next
Else
Msgbox Err.Description,vbExclamation,&quot;Error &quot; & Err
End if

'=========================

If that doesn't work then try disabling your error handlers to find out where the message is coming from.

And if that doesn't work, we'll try something else.


 
Thank you ITMannie and Jeremy for getting back to me.

I'm embarrassed to say that the problem was my fault. The &quot;No current record&quot; came from the NewInvoices function. I had the recordset MoveFirst without doing the RecordCount so when there is no record in the query, it displays the &quot;No current record&quot; message.

Sorry for taking your time to help me with that problem.
Thank you ITMannie for your solution to my first problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top