Hi,
I have a class I built for sending emails, it works fine, however, I have come across an anomaly I cannot fathom.
Part of the funcitonality is to show a progress window, which is initialised as follows...
This first time I use the email object everything is fine, the email works, the progress windows shows the steps, everything is dandy.
However, if I re initialise the same object to send a second email..
EG...
The error is actually happening in the show progress method on this line...
Why? the form opens like it usually should but the control is blank and the class crashes when trying to update with the progress message, yet it works fine first time round.
So how come the code works first time but not second time?
Thanks,
1DMF
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
I have a class I built for sending emails, it works fine, however, I have come across an anomaly I cannot fathom.
Part of the funcitonality is to show a progress window, which is initialised as follows...
Code:
Private Sub Class_Initialize()
' Progress window
bShowProgress = True
Set oProgress = CreateObject("Scripting.Dictionary")
oProgress.Add "Msg", cProgressMsg
Call InitProgress("Progress_Info", "Progress", False, True)
End Sub
' Initialise progress window
Public Sub InitProgress(ByVal sFormName As String, ByVal sTextCtrl As String, ByVal bHide As Boolean, ByVal bClose As Boolean, Optional ByVal sSubFormName As String = "")
'On Error Resume Next
Dim cTextBox As Access.TextBox
' Open form if not open
If Not CurrentProject.AllForms(sFormName).IsLoaded Then
DoCmd.OpenForm sFormName, acNormal
End If
' Hide form
If bHide Then
Forms(sFormName).Visible = False
End If
' Set textbox control
If sSubFormName <> "" Then
Set cTextBox = Forms(sFormName).Controls(sSubFormName).Form.Controls(sTextCtrl)
Else
Set cTextBox = Forms(sFormName).Controls(sTextCtrl)
End If
' Set progress vars
oProgress.Add "Frm", sFormName
oProgress.Add "Ctrl", cTextBox
oProgress.Add "Close", bClose
oProgress.Add "Hide", bHide
End Sub
' Show progress message
Private Sub ShowProgressMsg(ByVal bHide As Boolean)
On Error GoTo EH_ShowProgressMsg
' Check if form open
If Not CurrentProject.AllForms(oProgress.Item("Frm")).IsLoaded Then
DoCmd.OpenForm oProgress.Item("Frm"), acNormal
End If
' Check if form visible
If Not Forms(oProgress.Item("Frm")).Visible Then
Forms(oProgress.Item("Frm")).Visible = True
End If
' Update message window
oProgress.Item("Ctrl").Value = Nz(oProgress.Item("Ctrl").Value, "") & oProgress.Item("Msg").Item(oProgress.Item("Msg").Count) & vbCrLf
' Move cursor
oProgress.Item("Ctrl").SelStart = Len(oProgress.Item("Ctrl").Value)
' Hide message window if required
If bHide And oProgress.Item("Hide") Then
Forms(oProgress.Item("Frm")).Visible = False
End If
' Ensure screen is refreshed
DoEvents
Exit Sub
EH_ShowProgressMsg:
MsgBox "Error shwoing message : " & Err.Source & " - " & Err.Description & " - " & Err.Number
End Sub
This first time I use the email object everything is fine, the email works, the progress windows shows the steps, everything is dandy.
However, if I re initialise the same object to send a second email..
EG...
Code:
Dim oEmail as New clsEMailWrapperII
oEmail.Subject = "Hello World"
oEmail.To = "me@mydomain.com"
oEmail.Body = "This is an email"
oEmail.Create
oEmail.Send
' HERE IS WHEN I REUSE THE OBJECT
Set oEmail = new clsEmailWrapperII
oEmail.Subject = "Hello World Again"
oEmail.To = "me@mydomain.com"
oEmail.Body = "This is another email"
' THIS IS WHEN IT ERRORS....
oEmail.Create
The error is actually happening in the show progress method on this line...
Code:
' Update message window
oProgress.Item("Ctrl").Value = Nz(oProgress.Item("Ctrl").Value, "") & oProgress.Item("Msg").Item(oProgress.Item("Msg").Count) & vbCrLf
Why? the form opens like it usually should but the control is blank and the class crashes when trying to update with the progress message, yet it works fine first time round.
So how come the code works first time but not second time?
Thanks,
1DMF
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music