Adding a timer in VBA code

G

Guest

Im using the following code

If Date >= (InvoiceCreatedDate + invoicepaidbydayscombo.Value) And
Combo73.Value = "Invoice Sent" Then
Dim Response5 As Byte
Response5 = MsgBox("Invoice Has Not Been Paid. Would you Like To
Print Payment Reminder Letter? ", vbInformation + vbYesNo, "Job Manager")
If Response5 = vbYes Then
DoCmd.OpenReport "Request For Overdue Payment", acViewNormal, "",
"", acNormal
Combo73.Value = "Payment Request Sent" 'Status to Payment Request
Sent.
PaymentReminderPrintedDate.Value = Date 'Current Date.
DoCmd.Close acForm, "frmWorkOrders", acSaveYes 'Close WO Form.
DoCmd.OpenForm "frmWorkOrders", acNormal, , , , acHidden 'Open WO
Form Hidden.
Else
End If
End If

the code stops at DoCmd.Close acForm, "frmWorkOrders", acSaveYes 'Close WO
Form. The code is trying to close the form whilst a report is being
generated/printed from the form. Is there any way i can introduce a timer
into the code which will allow the report to run before trying to close the
form?
 
D

Douglas J. Steele

The fact that you're trying to open a report shouldn't affect the ability to
close the form. Are you getting an error message? If so, what is it?

Is there a reason for the acSaveYes, btw? You do realize that saves design
changes to the form, not any data you might have changed while the form was
open.
 
G

Guest

I have removed the acSaveYes from my code and the error is still coming up.
Runtime error 2585, ths action cant be carried out while processing a form or
report.
 
A

Arvin Meyer [MVP]

I use the following in a standard module:

Public Function Delay(dblInterval As Double)
On Error GoTo Err_Handler
Dim Timer1 As Double
Dim Timer2 As Double

Timer1 = Timer()
Do Until Timer2 >= Timer1 + dblInterval
DoEvents
Timer2 = Timer()
Loop

Exit_Here:
Exit Function

Err_Handler:
Resume Exit_Here

End Function

and then call it like this in the form:

Delay (0.5)

Whinch will introduce a half second delay while other procedures can run.
You can also look at the Windows Sleep API:

http://www.mvps.org/access/api/api0021.htm
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
G

Guest

Douglas,

After abit of investigation im guessing the code is causing the error as a
result of trying to close the form from the forms current event, any further
thoughts?
 
D

Douglas J. Steele

I don't understand why you'd be trying to close a form in its Current event.
That fires each time you go to a new record, including going to the first
record. In other words, the form would never open!

Perhaps you need to explain in words exactly what you're trying to do.
 
G

Guest

You will have to forgive me for my Access skills but im still on the learning
curve.

The form contains details of jobs, eg customer, materials, labour, price
etc. when the form opens and the current date exceeds the maximum time
allowed for the customer to pay, a msgbox appears asking if you want to print
a reminder letter for that perticular job, if you click yes, the the letter
is printed and the form is closed. basically the form never really opens. the
msgbox for the printing of the letter is fired off the current event, as
described in my vba code below. hope this gives you a better idea. if not i
will have to change my logic
 
D

Douglas J. Steele

See what happens if you move that logic into the form's Open event. There,
you can simply set Cancel = True, rather than having to actually close the
form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top