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 "MonthlyBillReport", acNormal
DoCmd.OpenReport "MonthlyBillReport_Reprint", 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.
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 "MonthlyBillReport", acNormal
DoCmd.OpenReport "MonthlyBillReport_Reprint", 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.