Send an email based on a report, from a specific form

Ole

Registered User.
Local time
Today, 13:31
Joined
Apr 15, 2012
Messages
44
:banghead:Hi

I'm trying to send at report based on a Query from a specific form.

Everything is (almost) working fine, except the fact that I can't get a criteria into DoCmd.SendObject method.

My code is:
-------
Private Sub Kommandoknap212_Click()

On Error GoTo MailTilGodkendelse_Err
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Dim MailAtt As String
Dim intSearch As String
intSearch = Betaler
MailAtt = DLookup("Mail", "Kundedatabase", "Firmanavn = '" & intSearch & "'")

stLinkCriteria = "Turnr=" & Me!Turnr
DoCmd.OpenReport File, acViewPreview, , stLinkCriteria, , acNormal
DoCmd.RefreshRecord
DoCmd.SendObject acReport, "Errand", "PDFFormat(*.pdf)", MailAtt, "", "", "New errand", "Please respond to this mail as soon as possible - Kind regards", True, ""

MailTilGodkendelse_Exit:
Exit Sub

MailTilGodkendelse_Err:
MsgBox Error$
Resume MailTilGodkendelse_Exit

End Sub
----

Any ideas?
 
Before I posted the thread I searched the forum and i found the link in earlier posts. And i dosen't Work for me.

And I forgot - these lines are disabled:
' stLinkCriteria = "Turnr=" & Me!Turnr
' DoCmd.OpenReport File, acViewPreview, , stLinkCriteria, , acNormal
So I don't have an open report. I'm trying to use a predefined report, based on a Query to open a specific form.
I try to get Me.Turnr from the form Kørselssystem to be the criteria for mailing the report (Errand).
Everything is working perfectly, except for the fact that I sending a report containing all the posts in the form (Kørselssystem).

Does it making any sence, what I'm writing here?
 
It makes sense, but apparently mine doesn't. You can open the report filtered first, then send it, then close it after, or use the method in the link. Not knowing what "doesn't work for me" means, I can't help figure that out.
 
My English might not be that good (I'm from Denmark), but what I meant was that I've tried the way you suggested, but I couldn't get it to Work with the code I have written until now.

I'm not familiar with first opening the report filtered, then send it and close it again.
 
I solved the problem by looking an extra time at the link you suggested, and then I was able to figure it out.

The final code:
-----
Private Sub Kommandoknap212_Click()
On Error GoTo MailTilGodkendelse_Err
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Dim MailAtt As String
Dim intSearch As String
Dim stLinkCriteria As String
Dim FileName2 As String

intSearch = Betaler
MailAtt = DLookup("Mail", "Kundedatabase", "Firmanavn = '" & intSearch & "'")

stLinkCriteria = "Turnr=" & Me!Turnr
FileName2 = "C:\Errands\Errand " & Me!Turnr & ".pdf"
DoCmd.OpenReport "Errand", acViewPreview, , stLinkCriteria, , acNormal
DoCmd.SendObject acReport, "Errand", "PDFFormat(*.pdf)", MailAtt, "", "", "New errand", "Please respond to this mail as soon as possible - Kind regards", True, ""
DoCmd.OutputTo acOutputReport, "Errand", acFormatPDF, FileName2, False
MsgBox "Specifikationen has saved in C:\Errands", vbOKOnly, "Information"
DoCmd.Close acReport, "Errand", acSaveYes

MailTilGodkendelse_Exit:
Exit Sub

MailTilGodkendelse_Err:
MsgBox Error$
Resume MailTilGodkendelse_Exit

End Sub
-------

A lot of thanks to you pbaldy :D
 

Users who are viewing this thread

Back
Top Bottom