Avatar of cozmo_troll
cozmo_troll

asked on 

Email Report from Form

I have a form setup for users to enter customer complaints. The form is setup so the main source is the customer table, the complaint is a subform. What I need is after the user is finished entering the complaint for them to push a button that then e-mails a report with information only pertaining to this complaint to some other employees. The e-mails will always be sent to the same people, so the user shouldn't have to define that. I am fine with the code starting an outlook application where the user would still have to push send.

Thank you!
Microsoft Access

Avatar of undefined
Last Comment
Jeffrey Coachman
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

cozmo_troll,

Here is a sample.

When you say "E-mail a report", you did not specify a format. (You cannot "send" Access objects by themselves, you have to export them out as a certain format)

Anyway... You should insert your own email wehre it says "DistributionList", to send the report to yourself as a test.

Let me know the outcome of the test.

Jeff
Access-EEQ23582779SendComplaintE.mdb
Avatar of cozmo_troll
cozmo_troll

ASKER

Jeff,

When I try this, it says Variable not found and highlights asformatSNP. Also, you can't have the report sent as the report format? If not, is there a way to print it to a PDF first before it attaches itself to the email?
cozmo_troll

Sorry, change it to:
acFormatSNP

"you can't have the report sent as the report format"
Again, there is no such thing.
Access objects cannot exist outside of the database container, they must be exported to a file.


"is there a way to..."
First, let's just see that if you fix the code, it will send the test email.
(And you recieve it)

JeffCoachman
Avatar of cozmo_troll
cozmo_troll

ASKER

Jeff,

OK, yes this attaches a 'snp' file to an e-mail with "distribution list" in the To field.


cozmo_troll,

You were supposed to substitute your email address for "distributionList"

Something like this:
DoCmd.SendObject acSendReport, "rptComplaints", asformatSNP, "cozmo@troll.com", , , "Recent Complaint!", "Here is the most recentComplaint: ", True
(But, I guess if your Distribution list is named "Distribution List", this would work.)

So,
please confirm:
 The email was sent and recieved?

;-)

JeffCoachman
Avatar of cozmo_troll
cozmo_troll

ASKER

Ok, yes, the e-mail will send/receive. However, can I get a PDF format rather than whatever snp is?

Thanks!
Avatar of cozmo_troll
cozmo_troll

ASKER

When I import the code into my own file, I get an error. Below is my code:
Private Sub Command69_Click()
Forms!FrmMain![tblQAIssue Subform].SetFocus
If [tblQAIssue Subform].Form.Dirty = True Then
    [tblQAIssue Subform].Form.Dirty = False
End If
Forms!FrmMain![tblQAIssue Subform].SetFocus
'DoCmd.OpenReport "tblCustomer", acViewPreview
DoCmd.SendObject acSendReport, "tblCustomer", acFormatPDF, "fakeemail@e-e.com", , , "Recent Complaint!", "Here is the most recentComplaint: ", True
End Sub

It comes up with: Runtime Error2465. Microsoft Access office cannot find the field "|" referenced in your expression. And when I debug it highlights the line >>If [tblQAIssue Subform].Form.Dirty = True Then

I tried troubleshooting and it will work fine if I completely eliminate this part:
Forms!FrmMain![tblQAIssue Subform].SetFocus
If [tblQAIssue Subform].Form.Dirty = True Then
    [tblQAIssue Subform].Form.Dirty = False
End If
However, then it sends all records rather than just the one relating to this one.

Thanks,
cozmo_troll,

"rather than whatever snp is?"
LOL
;-)

Yes, *however*, this requires you to create an email from scratch.
(more complicated)

Also, because Access 2003 and earlier cannot, on it's own, create PDF files, you need a PDF creation program.

That being said; do you already have a utility to create PDF's.
This program would have to support being used through VBA to create and name PDF's from code.
(And you would have to know how to do this, because I might use a different program.)
(this complicates things even more)

Do you "really" need a PDF?

Because the "Snapshot" (acFormatSNP) files are similar in that they cannot be edited. Any recipient would need MS Office installed.
Then there is the HTML format, this also cannot be edited directly.
All you need to view it is a Web Browser (which every computer has)

Using either of these two will make this as simple as the code I posted.
(Reccommended strongly)

If you really need to use a PDF, then be prepared to do a lot of research on your PDF program and it's interaction with VBA.
Not to mention getting familiar with creating Emails with VBA Code.

JeffCoachman
Avatar of cozmo_troll
cozmo_troll

ASKER

No, I don't NEED PDF; I was able to make HTML work fine, SNP does not work fine. However, the HTML file gets all mumbled up, doesn't keep nice clean formatted look of the main report which is the primary thing I do need it to have.
cozmo_troll,

What version of Access ar you using?
2007?
Because, there is no acFormatPDF in Access 32003 or lower.

1. The first error you are getting says that you have referenced the subform incorrectly.
You must double check this.

2. in your code you are using references a table "tblCustomers", you should be referencing a Report, because the code is:
    DoCmd.SendObject acSendREPORT

(I will notify the staff to remove your real email fom this post)
;-)

JeffCoachman
Avatar of cozmo_troll
cozmo_troll

ASKER

Jeff,

Like I said, HTML is fine as long as it carries the professional looking format. Also tblCustomers is the name of the report... I know it is not 'technically' right to do that, but it just carried that name when the report was named during the wizard process.

Thank you
OK,

Can you confirm what version of Access you are using?

JeffCoachman
Avatar of cozmo_troll
cozmo_troll

ASKER

2003
Then after you fix your referencing issue, you should be good to go with the SendObject code, just pick the format you want. (I would reccommend the snapshot format.)

If you need help let me know

JeffCoachman
Avatar of cozmo_troll
cozmo_troll

ASKER

Jeff,

I don't understand. First, it will not send just the record I am working with. Secondly, no matter what format I use it jumbles up the report and doesn't keep it's same format.

Thank you,
Avatar of cozmo_troll
cozmo_troll

ASKER

Do I have to do something on the On Open event of the report to make it only pull the record of the record I am wanting to send from the form?
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
So it is working OK now?
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo