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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to open reports dealing with time format

Status
Not open for further replies.

jalge2

Technical User
Feb 5, 2003
105
US
Scenario. I'm creating an AutoScheduler that will open certain reports at certain times. This will run constantly in the background. I've tried two different things. One is

If Time = #8:00:00 AM# Then
DoCmd.openreport "printlog", acViewNormal

ElseIf Time > #8:00:00 AM# Then
DoCmd.openreport "New Report", acViewNormal

and the other is

Dim TheHour As Integer
TheHour = Hour(Now)

If TheHour >= 8 And TheHour <= 9 Then
DoCmd.openreport &quot;Printlog&quot;, acViewPreview
ElseIf TheHour >= 11 And TheHour <= 24 Then
DoCmd.openreport &quot;New Report&quot;, acViewPreview
End If

I need a little help. Both will not print or open the report. What am I doing wrong?





 
Your code looks fine.

Can you find out if your scheduler is actually calling either of the report opening techinques?

Have you tried settings breakpoints in either the timer or in the code you've shown here?
 
I tested your code by placing a msgbox in both sides of the else statements. It gave me the proper message based on the time.

I put the code in a form's Timer event, and set the Timer Interval to 2000 (2 seconds). Popped up the message every time.

I suggest you do that also (MsgBox) to verify the time logic. Then you are down to a problem with the report itself.

Code on!!! Anthony J. DeSalvo
President - ScottTech Software
&quot;Integrating Technology with Business&quot;
 
beetee, it's actually a macro running named autoexec, all the macro is told to run openmodule &quot;openreport&quot;, which is the module that distinguishes between time.

I'm not exactly sure how to use msg boxes, I'm a very new access user with Lowe's Home Improvement. So I'm starting out here grasping straws. So I appreciate the help.
 
It's difficult to judge the problem without seeing the database. However, I can maybe help with the debugging.

A useful debugging statement is the 'Stop' Statement, e.g.

Public Function PrintReports()
Dim TheHour As Integer
TheHour = Hour(Now)
Stop
If TheHour >= 8 And TheHour <= 9 Then
DoCmd.openreport &quot;Printlog&quot;, acViewPreview
ElseIf TheHour >= 11 And TheHour <= 24 Then
DoCmd.openreport &quot;New Report&quot;, acViewPreview
End If
End Function

When you run your code, it will halt at the stop statement. Using this statement, you can find out if your code is actually running.

I'm guessing that your AutoExec macro has a RunCode command that invokes the print report function. Now you can find out if the print report function is actually running, and step through the code to find out what it's doing.

Also, you can use the 'immediate' window to help debugging. You can open it by pressing ^G. Once you have the window open, you can view variables, or enter statements, such as:
print TheHour

you can also send output to the immediate window from your code by using
debug.print TheHour

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top