Private Sub Form_Timer()
Static intShowStatus As Integer
If intShowStatus Then
' Show status.
lblStatus.Visible = True
Else
' Don't show icon.
lblStatus.Visible = False
End If
intShowStatus = Not intShowStatus
End Sub
Function MailBoxOwner()
On Error GoTo errHandler
'Declare objects & variants
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strMailBoxOwner As String
Dim strMailBoxOwnerTemp As String
Dim strEmail As String
Dim fMain As Form
'Set objects & variants
Set db = CurrentDb()
strSQL = "SELECT MailBox, EMAIL " _
& "FROM tbl_OUTLOOK_DELEGATE_ACCESS " _
& "GROUP BY MailBox,EMAIL " _
& "ORDER BY MailBox "
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
Set fMain = Forms("frmMain")
fMain.ProgressBarA.Visible = True
fMain.ProgressBarB.Visible = True
fMain.lblStatus.Visible = True
fMain.TimerInterval = 100
'Loop thru recordset to populate the word document
With rs
.MoveFirst
Do Until rs.EOF
strMailBoxOwner = rs!MailBox
strEmail = rs!Email
'Progress bar update
fMain.ProgressBarB.Width = (fMain.ProgressBarA.Width / .RecordCount) * .AbsolutePosition
'Added
DoEvents
' Repaint the current form.
fMain.Repaint
'Added ************************
.MoveNext
CreateWordDoc strMailBoxOwner, strEmail
For lCounter = 1 To 750000: Next 'Added ************************
Loop
End With
'***************************************************************
' If you're at the end of the Customers recordset, then fill the
' progress bar completely and repaint the form.
If rs.EOF Then
fMain.ProgressBarB.Width = rs.RecordCount
fMain.Repaint
fMain.TimerInterval = 0
fMain.cmdReset.Visible = True
fMain.lblStatus.Visible = True
fMain.lblStatus.Caption = "Done!"
fMain.ProgressBarA.Visible = False
fMain.ProgressBarB.Visible = False
' Set the progress bar's width to zero. Repaint the form.
'ProgressBarB.Width = 0
fMain.Repaint
fMain.lblExecute.Visible = False
End If
'***************************************************************
' Close the recordset.
rs.Close
exitHere:
'Empty objects
Set db = Nothing
Set rs = Nothing
Exit Function
errHandler:
MsgBox "Error: " & Err.Number & vbNewLine & "Description: " & Err.Description & "", vbInformation, "Populate Letter"
GoTo exitHere
End Function
|