VBA Loop On Timer

abbaddon223

Registered User.
Local time
Today, 05:53
Joined
Mar 13, 2010
Messages
162
Hi all,

Hoping someone can help please...

I'm using the below code to activate an outlook event and send it to a customer. All this is working fine.

What I would like to do is add in an interval timer which, rather than firing out emails none stop (as this code does now) it waits XX seconds between each loop (to let the preceeding email send first).

I can get it to delay the start by using a timer in the form, but as soon as this comes round, email after email etc...

Thanks in advance..

Private Sub Form_Timer() '< me trying to get to work of form timer'
Do
If IsNull(Me.EmailAddress) Then
MsgBox "End Of Email", vbInformation, "Update"
Exit Sub
End If
Dim olk As Outlook.Application
Set olk = CreateObject("Outlook.application")
Dim olkmsg As Outlook.MailItem
Set olkmsg = olk.CreateItem(olMailItem)
With olkmsg
Dim olkrecip As Outlook.Recipient
On Error Resume Next
Set olkrecip = .Recipients.Add(Me![EmailAddress])
olkrecip.Type = olTo
.Subject = (Me![SubjectLine])
On Error Resume Next
.Display
Rem .Send
End With
On Error Resume Next
Set olk = Nothing
Set olkmsg = Nothing
Set olkrecip = Nothing
[Sent].Value = "Yes"
[DateSent].Value = Date
DoCmd.GoToRecord acDataForm, "Form1", acNext
Loop
End Sub
 
Why are you using a loop inside a timer event? Get rid of the Do Loop, the timer will automatically call itself every X seconds which seems like what you want it to do.
 

Users who are viewing this thread

Back
Top Bottom