Auto Email based on Field Criteria

Kereng

Registered User.
Local time
Today, 22:12
Joined
Feb 8, 2011
Messages
19
Hi,

I have a data entry form that, when completed, I need to send as a report via automatic email. I have created a report that pulls the relevant information and I know I can use 'Send Object' in the 'Before Update' event to send it. However, I need to change the 'To' email address based on a selection in a specific field in the data entry form.

For example, if the 'Supplier' field is 'Supplier X' I want the email to go to the contact for that company. If it's 'Supplier Y' I want the email to go to that supplier instead. The 'Supplier' field pulls through (via a lookup) information from the 'Supplier Table'.

Is there an easy way to send the email based on that criteria? I am not familiar with VBA.
 
Have a look at DoCmd.SendObject. You can populate all the required criteria by referencing your calling form.

Here is some code that I use to email reports to clients;
Code:
    If IsNull([Email]) Then
        MsgBox "Please enter an Email Address or amend the client details" & vbCrLf & "to include a valid email address"
        Me.Email.SetFocus
        Exit Sub
    End If

    Dim stDocName As String
    Dim stDocName3 As String

    stDocName = "RPT_Email"
    stDocName3 = "FRM_DbkEmail"
    
    DoCmd.SendObject acReport, stDocName, acFormatSNP, [Email], , , "Drawback " & vbCrLf & [PSRef], [Text7] & vbCrLf & [EmailMsg]
    
    DoCmd.Close acForm, stDocName3
 

Users who are viewing this thread

Back
Top Bottom