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

CresolZim

Registered User
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

error reading drive A:
Joined
May 7, 2009
Messages
8,631
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
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

error reading drive A:
Joined
May 7, 2009
Messages
8,631
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
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

error reading drive A:
Joined
May 7, 2009
Messages
8,631
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
Joined
Jul 9, 2003
Messages
10,849
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
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
Joined
Jul 9, 2003
Messages
10,849
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://sellfy.com/p/tZxO/

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

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom