Hi all, me again, I have looked all day on how to accomplish this without success also. I was able to create a VBA code to send email based on a combobox that when updated it produces a email for the person that is being choosen. So, i tried to re-work this same code to try to accomplish what I will describe below:
tblEmployees:
Employee name (PK)
e-mail
job position
team
I have a form in which the user input data and click a button to update the DB.
I have also a query that returns the records that was included in that day and a report based on this query called ReportSupervisor
I wish that when the user click the button, an email with this report is sent to the email registered in tblEmployees if the job position is = to Supervisor
I tried the following code:
Code:
Private Sub Comando87_Click()
Dim sSubject As String
Dim stMail As String
Dim strBody As String
'message subject
sSubject = "New information included for your evaluation"
'sends email to whoever is described as supervisor in tblEmployees
stMail = DLookup("[e-mail]", "tblEmployees", "[job position]= Supervisor")
'email body
strBody = "See email attached for additional information"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.SendObject acSendReport, ReportSupervisor, acFormatPDF, , , , sSubject, strBody, True
End Sub
When I tried this code I get an error message:
Error in execution time '3075'
Sintaxe error (missing operator) in de query expression '[job position]= Supervisor'
and it highlights the line: stMail = DLookup("[e-mail]", "Employees", "[job position]= Supervisor")
I dont understand almost nothing (barely nothing) on VBA codes, so please forgive me if I am asking something that is basic or making basic mistakes that I am not being able to see
.
If possible also, I would like to send two reports on this, so could I repeat the DoCmd.SendObject line changing the name of the report for the other one that I want?
Is there any other code that could do this task easily?
I have two of my questions that I was able to accomplish my goal thanks to this forum, so I am always backing here for be save!!! Thank you in advance!!