473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Using SendObject and capturing text from fields to add to outlook.

I have a form with a Command button set up to email the current record/invoice as a report, and as an attached document. It works well. However, I have in the underlying invoices table, and email address field (which is also on the form) and I would like Access to automatically add that email address for that specific invoice to Outlook's "To:" field, just like it attaches the current invoice.
This is my current VBA code.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command55_Click()
  2.  
  3.     DoCmd.RunCommand acCmdSaveRecord
  4.  
  5.     DoCmd.OpenReport "rptINVOICES", acPreview, , "[ORDER ID]=Forms!frmQUOTES![ORDER ID]"
  6.     DoCmd.SendObject acReport, "rptINVOICES", "PDFFormat(*.pdf)", "", "", "", "", "", True, ""
  7.  
  8.  
  9.  
  10. End Sub
Thanks ahead of time for your help.
Feb 26 '13 #1
5 4716
zmbd
5,501 Expert Mod 4TB
You would use the send object; however, select the email...
While in your VBE you can press [F1] and search, or follow this link:
>> DoCmd.SendObject Method (Access) Office 2010

As for your email, you will need to use either dlookup() and find the email that way, or, depending on your form you may be able to pull that information from your form controls


There is also outlook automation code which you may find more flexable.
Once again, you can find this information in the insights articles - go to the insight site map at the bottom of the page and take a look at #159
Feb 26 '13 #2
I'm stumped, I'll apologize ahead of time if I should be getting this.

I'd like to return the Customer email field from the tblOrders table for the record that is currently being displayed in the frmInvoices form to my "To" portion of my SendObject. It looks like below. Currently, I am only getting the code in the parenthesis to appear in the To field of the email.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.SendObject acReport, "rptINVOICES", "PDFFormat(*.pdf)", "[Customer Email]=Forms!frmQUOTES![ORDER ID]", "", "", "Mulch Quote", "Attached is a copy of your Zeager Quote or Order.  Thank you for contacting us.", True, ""
Feb 26 '13 #3
zmbd
5,501 Expert Mod 4TB
In this case, I'm going to have to see much more of the code than you posted. Having just that single line doesn't let me how you're accessing the data from your form.
Feb 26 '13 #4
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command55_Click()
  2.  
  3.     DoCmd.RunCommand acCmdSaveRecord
  4.  
  5.     DoCmd.OpenReport "rptINVOICES", acPreview, , "[ORDER ID]=Forms!frmQUOTES![ORDER ID]"
  6.     DoCmd.SendObject acReport, "rptINVOICES", "PDFFormat(*.pdf)", "[Customer Email]=Forms!frmQUOTES![ORDER ID]", "", "", "Mulch Quote", "Attached is a copy of your Zeager Quote or Order.  Thank you for contacting us.", True, ""
  7.  
  8.  
  9.  
  10. End Sub
Let me know if you need more information = Thanks zmbd for helping me numerous times - I feel like I'm learning a lot.
Feb 27 '13 #5
zmbd
5,501 Expert Mod 4TB
I don't normally do this... however, I'm feeling particularly nice today:

PetPeeve: 1st, MG this is not your fault -
A large number of texts and etc show to use the commands while building the string inline with them (as you attempted).
HOWEVER, one cannot easily trouble shoot the resolved string.

In your case, it as I thought, you are not retrieving the value from your form. You are in fact sending:
"[ORDER ID]=Forms!frmQUOTES![ORDER ID]"
as your value instead of (say you're on ID # 42:
"[ORDER ID]=42"

So... take a look at how I would write your code:

(* Warning: This is "air" code, in that I've written this from memory! *)
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command55_Click()
  2.     Dim zStrReport As String
  3.     Dim zStrSQL As String
  4.     Dim zStrSendTo As String
  5.     Dim zStrSubject As String
  6.     Dim zStrMessage As String
  7.     '
  8.     'Set error trap:
  9.     On Error GoTo zErrorTrap
  10.     '
  11.     'Make sure that any edits to the current record have been saved.
  12.     DoCmd.RunCommand acCmdSaveRecord
  13.     '
  14.     'I would like to open the following report:
  15.     zStrReport = "rptInvoices"
  16.     zStrSQL = "[ORDER ID] = " & Forms!frmQUOTES![ORDER ID].value
  17.     '
  18.     '
  19.     DoCmd.OpenReport ReportName:=zStrReport, AcView:=acNormal, WhereCondition:=zSQL
  20.     '
  21.     'Now let's send that in an email as a pdf
  22.     zStrSendTo = "changethisemail@mailinator.com"
  23.     zStrSubject = "Mulch Quote"
  24.     zStrMessage = "Attached is a copy of your Zeager Quote or Order.  Thank you for contacting us."
  25.     '
  26.     DoCmd.SendObject ObjectType:=acSendReport, ObjectName:=zStrReport, OutputFormat:=acFormatPDF, TO:=zStrSendTo, Subject:=zStrSubject, Messagetext:=zStrMessage, EditMessage:=True
  27.     '
  28.     '
  29. zExitFromError:
  30.     exitsub
  31. zErrorTrap:
  32. '
  33. 'uncomment the Stop line for troubleshooting.
  34. 'Stop
  35.     MsgBox "The following error occured while attempting to send: " & zStrReport & vbCrLf & _
  36.         "TO: " & zStrSendTo & vbCrLf & _
  37.         "Error Number: " & Err.Number & vbCrLf & _
  38.         "Error Detail: " & Err.Description, vbCritical + vbOKOnly, "Send Invoice Error"
  39. Resume zExitFromError
  40. End Sub
If I want to see how that zStrSQL is resolving I can place a debug.print zStrSQL on a line right below it and then after running, or during if I get an error and have the stop uncommented.

Now I can't debug and compile this on my system as I don't have your form and database so there may be a syntax error...
What you should do is comment out your code, copy and paste mine in there and then do a debug compile.

You should take note of a few things... The TO and Message can be customized based on values from your customer table and so much more... (the how to will either be a dlookup against the customer table, or pulled from the form's record set depening on how you have things setup) AND you can debug.print these strings to just in case you're not getting what you expect!

I've been able to include your report name in three places by defining it once. If you want to change the report name you only need to change it in one place and a few other items.
Feb 27 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to...
1
by: Alex | last post by:
Acc 97 Hi, I have the following in my query which works well if it is all set to numbers on table design. But what I want to do is where it states MC (short for machine name) use the actual...
2
by: Patrick de Ridder | last post by:
I can send (email_address,subject,text) to outlook express. What I can't do is retain the line breaks. Could anyone please tell me how to do that? Sending "\r\n" doesn't force line breaks. ...
4
by: Krishna Kumar | last post by:
Hai all, I am doing a project in .net and in that project I have a problem in capturing text from an image. i.e images like CAPTCHA images . which has inbuilt text with in the image.So,...
3
by: Frustrated Developer via DotNetMonster.com | last post by:
I have posted a couple times on here already and found the user community to be very helpful. I took on a project before I realized how difficult a time I'm having working with a database....
0
by: Ennio-Sr | last post by:
Hi all! After a very long struggle I finally succeded in transferring my old *.dbf file and the relating *.dbt (alias memo fields) to a pg table. For the time being I put the memo field in a...
2
by: JohnR | last post by:
When creating an msAccess db within the Access UI itself the fields that are text are NOT padded with blanks. For example, if I have a 10 char field and put in "HI" and then when I come back to...
1
by: rick m | last post by:
We have an access DB that 2 input people use to tracking incoming patients. There is a form for them to do this but they find it confusing to use (it's plainly laid out, no one else complains about...
2
by: Duk Lee | last post by:
What is the most elegant way to clear all the text fields on asp.net page? I just don't think that txtShortName.Text = "" txtYearFounded.Text = "" txtCompanyCode.Text = "" txtCity.Text = ""...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.