Holly_Associated
Registered User.
- Local time
- Today, 02:47
- Joined
- Mar 21, 2013
- Messages
- 53
Hi everyone,
I have a problem with some code, I am quite new to VBA! I have searched the forums and tried a few things myself and cannot find an answer. I'm using 2013.
The first version of my code works great. It opens the correct report and attaches it to an e-mail as a pdf with all of my text etc.
The problem I have is I would like to rename the pdf, so instead of "RptJobDSD" everytime, it can have some fields [DSDDate] and [JobID] etc.
Before trying the fancy field stuff I thought I'd try just "DSD Test" and see if I could rename it in the first place!
I added this and am getting - Error(32004) - The control name 'RptJobDSD' is misspelled or refers to a control that doesn't exist.
My confusion comes as the OpenReport and SendObject recognise strReport why doesn't SetProperty?! :banghead:
I have a problem with some code, I am quite new to VBA! I have searched the forums and tried a few things myself and cannot find an answer. I'm using 2013.
The first version of my code works great. It opens the correct report and attaches it to an e-mail as a pdf with all of my text etc.
Code:
Private Sub btnEMail_Click()
On Error GoTo errHandler
Dim strReport As String
Dim vMsg As String
Dim vSubject As String
Dim strWhere As String
strReport = "RptJobDSD"
strWhere = "DSDID = " & Forms!FrmMenu!NavigationSubform!SubFrmJobDSD!DSDID
vMsg = Trim("Please find attached your daily site diary for ")
vSubject = Trim("Daily Site Diary for ")
DoCmd.OpenReport strReport, acViewPreview, , strWhere
DoCmd.SendObject acSendReport, strReport, acFormatPDF, , , , vSubject, vMsg, True
exitOnErr:
Exit Sub
errHandler:
If Err.Number <> 2501 Then MsgBox "Error (" & Err.Number & ") - " & Err.Description, vbCritical
Resume exitOnErr
End Sub
The problem I have is I would like to rename the pdf, so instead of "RptJobDSD" everytime, it can have some fields [DSDDate] and [JobID] etc.
Before trying the fancy field stuff I thought I'd try just "DSD Test" and see if I could rename it in the first place!
I added this and am getting - Error(32004) - The control name 'RptJobDSD' is misspelled or refers to a control that doesn't exist.
Code:
DoCmd.OpenReport strReport, acViewPreview, , strWhere
[COLOR=blue]DoCmd.SetProperty strReport, acPropertyCaption, "DSD Test"
[/COLOR] DoCmd.SendObject acSendReport, strReport, acFormatPDF, , , , vSubject, vMsg, True
My confusion comes as the OpenReport and SendObject recognise strReport why doesn't SetProperty?! :banghead: