Emailing multiple payslips to several employees at once (1 Viewer)

CresolZim

Registered User.
Local time
Today, 16:17
Joined
Mar 22, 2019
Messages
11
I have developed a payroll program in Access . I have the payslip report based on a query.Each employee table has an email field. Using the Sendobject Im able to send emails to each employee individually. I need Assistance for a procedure that will allow a individual payslips to be sent to several individual employees on one click.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:17
Joined
May 7, 2009
Messages
19,169
use recordset:
Code:
With Currentdb.Openrecordset("employeeTableName", dbopensnapshot)
    .MoveFirst
    While Not .EOF
        docmd.SendObject  To:=!email_adrress_Field
        .MoveNext
    Wend
End With
 

CresolZim

Registered User.
Local time
Today, 16:17
Joined
Mar 22, 2019
Messages
11
Thank You for Your Advice and code. Ive tested the code on a sample but the email has blanks.
This is my sample code:
Private Sub Command0_Click()
Dim DBSEmailSample As Database
Dim rstPayslips As Recordset
Dim prploop As Property
Dim Y As String
Set DBSEmailSample = OpenDatabase("emailSample.accdb")
Set rstPayslips = DBSEmailSample.OpenRecordset("QryRep", dbOpenSnapshot)
Y = rstPayslips!Email
With CurrentDb.OpenRecordset("QryRep", dbOpenSnapshot)
.MoveFirst
While Not .EOF
DoCmd.SendObject , Y
.MoveNext
Wend
End With

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:17
Joined
May 7, 2009
Messages
19,169
Code:
Private Sub Command0_Click()
    Dim DBSEmailSample As dao.Database
    Dim rstPayslips As dao.Recordset
    Dim prploop As Property
    Dim Y As String
    Set DBSEmailSample = OpenDatabase("emailSample.accdb")
    Set rstPayslips = DBSEmailSample.OpenRecordset("QryRep", dbOpenSnapshot)
    With rstPayslips
        If Not (.BOF And .EOF) Then .MoveFirst
        While Not .EOF
            Y = rstPayslips!Email
            DoCmd.SendObject To:=Y, Subject:="Payslip", MessageText:="Your payslip for this month", _
                            Objecttype:=acSendReport, ObjectName:="theNameOfReport", OutputFormat:=acFormatPDF
            .MoveNext
        Wend
        .Close
    End With
    Set rstPayslips = Nothing
    Set DBSEmailSample = Nothing
End Sub
 

CresolZim

Registered User.
Local time
Today, 16:17
Joined
Mar 22, 2019
Messages
11
Thank you. The code Works. The only snag is that the payslip Report has the payslips for all the employees. And this is sent to each employee , and thats not a good idea.

I have a procedure for selecting individual employees but this is not appropriate as I have to send each individual payslip one at a time.
The other problem is that the code only moves to movenext after I have pressed the send button in outlook.If Im sending 40 payslips I want to press send Once.
I appreciate your assistance and patiance
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:17
Joined
May 7, 2009
Messages
19,169
if outlook is stalling the code. you could try to use Outlook automation on sending mail, rather than using SendObject.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 14:17
Joined
Jul 9, 2003
Messages
16,244
In this Blog on Nifty Access:-

https://www.niftyaccess.com/generate-multiple-reports/


I demonstrate a method of creating a single report from a set. Basically you have a template report, to which you send an SQL string which controls what is displayed on the Report.

The SQL string is created by two recordset loops, one loop extracts each users details and the other extracts the particular record details related to that user. In your case, the payslip details.

If you want some help adapting it to your situation I'm available this weekend.





Sent from my Pixel 3a using Tapatalk
 

CresolZim

Registered User.
Local time
Today, 16:17
Joined
Mar 22, 2019
Messages
11
I think something like that will give me the results I want.What do I need to do to get more details
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 14:17
Joined
Jul 9, 2003
Messages
16,244
I think something like that will give me the results I want.What do I need to do to get more details

Assuming you are referring to my post, have you looked at the information on the Nifty Access website?

Please note the Access example file can be downloaded from here:-

https://gum.co/GenerateMultipleReports

To get it for free, use Coupon Code:- rgjpx58
 
Last edited:

Users who are viewing this thread

Top Bottom