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

Newbie needs workable Pause function 1

Status
Not open for further replies.

bufbec

Technical User
Jun 3, 2003
2
US
I have some code modified from the Microsoft knowledge base. I have a 7 page report that I need to collate and print to 300 people. The code that I have (and it works) is:
Function CollateReports(NumPages, Rpt1 As String, Rpt2 As String, Rpt3 As String, Rpt4 As String, Rpt5 As String, Rpt6 As String, Rpt7 As String)
Dim MyPageNum As Integer
'Set the page number loop and alternate printing the report pages.
For MyPageNum = 1 To 5 'if you input 1 to 5, it will print and collate the first 5 records of each report
'NumPages is the number of pages to print.

DoCmd.SelectObject acReport, Rpt1, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt2, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt3, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt4, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt5, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt6, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt7, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum

Next MyPageNum
End Function

then, I have to go to the immediate window, input the command below, which causes the module to run and print my reports:
?CollateReports(1, "Peds Page 1","Peds Page 2","Peds Page 3","Peds Page 4","Peds Page 5","Peds Page 6","Peds Page 7")

Problem: Data is sent to the printer too fast and everything gets jumbled after awhile. I have searched and found various coding for a 'Wait' or a 'Pause; however, I cannot figure out how to incproprate it into the above code. I get an error every time. The coding for thie (I believe) has to be embedded within the above code somewhere, to cause the program to pause for 30 seconds before it loops and starts again.

Can anyone help me? Please let me know if you need more information. Thank you.
 
Add this procedure to a public module

Sub basPause(intSec As Integer)
Dim lngTimerValue As Long

lngTimerValue = Timer
Do Until Timer - lngTimerValue >= intSec
Loop
End Sub



Function CollateReports(NumPages, Rpt1 As String, Rpt2 As String, Rpt3 As String, Rpt4 As String, Rpt5 As String, Rpt6 As String, Rpt7 As String)
Dim MyPageNum As Integer
'Set the page number loop and alternate printing the report pages.
For MyPageNum = 1 To 5 'if you input 1 to 5, it will print and collate the first 5 records of each report
'NumPages is the number of pages to print.

DoCmd.SelectObject acReport, Rpt1, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt2, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt3, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt4, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt5, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt6, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, Rpt7, True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum

basPause(30)

Next MyPageNum
End Function
 
One way - somewhat crude would be to put a "Y/n" MsgBox between the DOCmd's above and allow the user to Press the 'Y' or even a MsgBox Ok


Does that help?

rollie@bwsys.net
 
xmad4:
thanks for the quick reply. I tried this, and get an error:
compile error: expected variable or procedure, not module

I wasn't sure what you meant by 'public' module, so i just created a new module that I called 'basPause' where I copied your code, and then entered the single line of code into my 'collate reports' module.

Any ideas??
 
Create a module called Module1. A module can't have the same name as a sub or function and insert the basPause procedure into that.
 
or just rename the basPause module to something else..
 
Try this code. It frees up more system resources and deals with midnight. I didn't actually understand the other code posted (not a slight--I just didn't understand it), so I don't know if it accounts for midnight. But in any case, the DoEvents statements will make your other code run more smoothly with this function.

I didn't write it, as is made clear in the comment. I don't know where Trevor's web site is these days, but he's a sharp-as-could be programmer, and a hugely valuable member of the Access developer community.

Jeremy


Sub WaitFor(psngSeconds As Long)
' wait for specified number of seconds
' Copyright Trevor Best (trevor@besty.org.uk)

Dim sngStart As Single
Dim sngET As Single

sngStart = Timer
DoEvents
Do While sngET < psngSeconds
DoEvents
' check for midnight as the Timer() function will
' rollover at this point
sngET = Timer - sngStart
If sngET < 0 Then
' it rolled over - add number of seconds
' in a day
sngET = sngET + 86400
Beep
End If
' now don't hog the processor
' release some CPU slices back to Windoze
DoEvents
Loop
End Sub


==
Jeremy Wallace
AlphaBet City Dataworks
Affordable Development, Professionally Done

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top