Sending Email form report (1 Viewer)

whojstall11

Registered User.
Local time
Today, 12:31
Joined
Sep 7, 2011
Messages
94
I am trying to send an Email from a report . Using this code
Code:
On Local Error GoTo Some_Err
    
    Dim MyDB As Database, RS As Recordset
    Dim strBody As String, lngCount As Long, lngRSCount As Long
    
    DoCmd.RunCommand acCmdSaveRecord
    Set MyDB = DBEngine.Workspaces(0).Databases(0)
    
    Me!txtProgress = Null

   Set RS = MyDB.OpenRecordset _
      ("Email - Outstanding Promos")
    lngRSCount = RS.RecordCount
    If lngRSCount = 0 Then
      MsgBox "No promo email messages to send.", vbInformation
    Else
      RS.MoveLast
      RS.MoveFirst
      Do Until RS.EOF
        lngCount = lngCount + 1
        lblStatus.Caption = "Writing Message " & CStr(lngCount) _
          & " of " & CStr(lngRSCount) & "..."
        strTo = RS!cEmailAddress
        intMessageID = Year(Now) & Month(Now) & Day(Now) & Fix(Timer) & "_MabryMail"

        ' Send the email using some technique or other

        RS.Edit
        RS("cpeDateTimeEmailed") = Now()
        RS.Update
        RS.MoveNext
      Loop
    
    End If
    RS.Close
    MyDB.Close
    Set RS = Nothing
    Set MyDB = Nothing
    Close
    
    Me!txtProgress = "Sent " & CStr(lngRSCount) & " emails."
    lblStatus.Caption = "Email disconnected"
    MsgBox "Done sending Promo email. ", vbInformation, "Done"
    lblStatus.Caption = "Idle..."
    Exit Sub
    
Some_Err:
    'MousePointer = 0
    MsgBox "Error (" & CStr(Err.Number) & ") " & Err.Description, _
        vbExclamation, "Error!"
    lblStatus.Caption = "Email disconnected"
    End Sub

Im getting an error on lblStatus.Caption. I guess im not understanding the code can somebody help.
 

pr2-eugin

Super Moderator
Local time
Today, 20:31
Joined
Nov 30, 2011
Messages
8,494
Is there a Label called lblStatus in your Report? If yes, make sure you have spelt it correctly and also show the exact error number and description..
 

whojstall11

Registered User.
Local time
Today, 12:31
Joined
Sep 7, 2011
Messages
94
Yes I have this in my report. Could it be
Code:
 lngCount As Long, lngRSCount As Long
I dont have these in my report. What should they refer to?
 

Attachments

  • ERROR.png
    ERROR.png
    17.8 KB · Views: 80
Last edited:

pr2-eugin

Super Moderator
Local time
Today, 20:31
Joined
Nov 30, 2011
Messages
8,494
No I am talking about lblStatus.. Which is actually actually causing the Error.

Can you show the Error Number and Description?
 

whojstall11

Registered User.
Local time
Today, 12:31
Joined
Sep 7, 2011
Messages
94
IT doesnt give the error number just the description. But I attached it to the last post.
 
Last edited:

pr2-eugin

Super Moderator
Local time
Today, 20:31
Joined
Nov 30, 2011
Messages
8,494
So if the control lblStatus does not exist in your report what are you referring to? If that is not required, delete the line of code.. If it is required, make sure you spell the Label control right. Go to the design view of the report, then click on the control.. In the Property window, copy the name of the control and use that there..
 

Users who are viewing this thread

Top Bottom