Solved Email syntax assistance

CharlesDavenport

New member
Local time
Today, 18:36
Joined
Dec 7, 2020
Messages
26
OK I have the below VBA to send a report but Im getting a syntax error on the DoCmd.Send.Object and trying to work out where ive gone wrong!

Ive had to list out all of the variables so that I can take the email address from a table of employee names based on the name on a form and ive gone wrong somewhere and ive been staring at this for so long i cant see the mistake!

Any assistance is appreciated.

Code:
Private Sub Submit_Click()

If (Forms!PersonalConflict!Check166.Value = -1) Then
    
    DoCmd.RunCommand acCmdSaveRecord
'-----------------------------------------------------

On Error GoTo 0
Dim InsOwner As String

InsOwner = DLookup("[Email]", "[Employee Names]", "[Employee Name] = '" & Me.Text405 & "'")


Dim emailTo As String
emailTo = "& InsOwner & ; Charles.davenport@.co.uk "


DoCmd.SendObject ObjectType:=acSendForm, ObjectName:=Forms![PersonalConflictPrint], OutputFormat:=acFormatPDF, To:=emailTo, CC:="", BCC:="", Subject:="NEW PERSONAL CONFLICT INFORMATION SUBMITTED", MessageText:="Please review the attached Personal Conflict Information for new client.", EditMessage:=False,

End If

End Sub
 
Debug.Print emailTo

Why would it start with an ampersand?
Your concatenation is all wrong?

Code:
emailTo = InsOwner & " ; Charles.davenport@.co.uk "
 
Thanks for pointing that out.... still not the route of my issue but im sure it was one of (possibly many) reasons
 
Worked it out myself.... I needed to create variables for everything when using this method ie.

Code:
Dim emailTo As String
Dim sCc As String
Dim SBcc As String
Dim sForm As String
Dim sSubj As String
Dim sMsg As String

emailTo = InsOwner & "; Charles.davenport@.co.uk "
sCc = ""
SBcc = ""
sForm = "PersonalConflictPrint"
sSubj = "NEW PERSONAL CONFLICT INFORMATION SUBMITTED"
sMsg = "Please review the attached Personal Conflict Informtion for the new client."

DoCmd.SendObject ObjectType:=acSendForm, ObjectName:=sForm, OutputFormat:=acFormatPDF, To:=emailTo, Cc:=sCc, Bcc:=SBcc, Subject:=sSubj, MessageText:=sMsg, EditMessage:=False
 

Users who are viewing this thread

Back
Top Bottom