473,399 Members | 3,919 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,399 software developers and data experts.

Can I output data from a query / table / form by email as apposed to attaching?

I have an Access Database that is used as an ordering system. At the minute, when the user hits the re-order button, the details required are passed to a sub which then passes these details into the body of an email and sends it. This works great but the problem is, one email equals one order. One of my users has now requested that multiple orders can be made on one click of the button. I have added a check box to the form and ideally I would like to loop through the table and add the info to the body of the email where the check box is marked true. Is this possible?
Oct 16 '13 #1
3 2897
ADezii
8,834 Expert 8TB
Yes, this should be possible but will need much greater detail. Table structure, Field Types, sample Data, E-Mail Client...
Oct 17 '13 #2
Poet
2
Assuming you're using Outlook and already have an idea of how to generate the body of the e-mail...

Sure, using Ron de Bruin's Outlook code for Excel and retrofitting it to Access: http://www.rondebruin.nl/win/s1/outlook/bmail4.htm

The basic steps would be:
  1. Include reference to Microsoft Outlook Object Library in the Access VBA IDE.
  2. Augment Ron's Mail_small_Text_Outlook function to include strBody in the function's arguments, so you can create the body outside of the mail function.
    Expand|Select|Wrap|Line Numbers
    1. Public Sub mailSend(Optional strTo As String, Optional strCC As String, Optional strBBC As String, _
    2.     Optional strSubject As String, Optional strBody As String, Optional varAttachmentFilepath As Variant, Optional boolSend As Boolean, _
    3.     Optional boolHTMLBody As Boolean, Optional strSendFromEmail As String)
    4. ' send an e-mail message (and optional attachment) via outlook
    5. ' adapted from code by ron de bruin of www.rondebruin.nl
    6.  
    7. Dim objOutlook As Object
    8. ' object for outlook application
    9.  
    10. Dim objMessage As Object
    11. ' object for outlook mail message
    12.  
    13. Set objOutlook = CreateObject("Outlook.Application")
    14. ' reference/open outlook
    15.  
    16. Set objMessage = objOutlook.CreateItem(0)
    17. ' create a new outlook mail message
    18.  
    19. With objMessage
    20. ' working with the new outlook mail message, ...
    21.  
    22.     .To = strTo$
    23.     ' set the recipients
    24.  
    25.     .CC = strCC$
    26.     ' set the carbon copy recipients
    27.  
    28.     .BCC = strBCC$
    29.     ' set the blind carbon copy recipients
    30.  
    31.     .Subject = strSubject$
    32.     ' set the subject
    33.  
    34.     If boolHTMLBody = True Then
    35.     ' if user requests to have the e-mail sent as an html e-mail, ...
    36.  
    37.         .BodyFormat = olFormatHTML
    38.         ' set the body format of the e-mail to html
    39.  
    40.         .HTMLBody = strBody$
    41.         ' set htmlbody of e-mail
    42.  
    43.     Else
    44.     ' if user does not want to have the e-mail sent as an html e-mail, ...
    45.  
    46.         .Body = strBody$
    47.         ' set the body
    48.  
    49.     End If
    50.  
    51.     If strSendFromEmail$ <> vbNullString Then .SentOnBehalfOfName = strSendFromEmail$
    52.     ' if user provided a from e-mail, set the sentonbehalfof e-mail
    53.  
    54.     If IsArray(varAttachmentFilepath) Then
    55.     ' if the attachment filepath is an array, ...
    56.  
    57.         If IsEmpty(varAttachmentFilepath) = False Then
    58.         ' if the attachment filepath array is not empty, ...
    59.  
    60.             For Each objAttachmentFilepath In varAttachmentFilepath
    61.             ' looping through each attachment filepath in the array, ...
    62.  
    63.                 If CStr(objAttachmentFilepath) <> vbNullString Then
    64.                 ' if the attachment filepath, converted to a string, is not blank, ...
    65.  
    66.                     .Attachments.Add objAttachmentFilepath
    67.                     ' add the attachment filepath to the array
    68.  
    69.                 End If
    70.  
    71.             Next objAttachmentFilepath
    72.             ' continue looping through the attachment filepath array
    73.  
    74.         End If
    75.  
    76.     Else
    77.     ' if the attachment filepath is not an array, ...
    78.  
    79.         If IsMissing(varAttachmentFilepath) = False Then
    80.         ' if an attachment filepath is possibly provided, ...
    81.  
    82.             If varAttachmentFilepath <> vbNullString Then
    83.             ' if an attachment filepath is provided
    84.  
    85.                 .Attachments.Add varAttachmentFilepath
    86.                 ' add the attachment
    87.  
    88.             End If
    89.  
    90.         End If
    91.  
    92.     End If
    93.  
    94.     If boolSend = True Then
    95.     ' if user wants to send the messsage, ...
    96.  
    97.         .Send
    98.         ' send the message
    99.  
    100.     Else
    101.     ' if user does not want to send the message, ...
    102.  
    103.         .Display
    104.         ' display the message
    105.  
    106.     End If
    107.  
    108. End With
    109.  
    110. Set objMessage = Nothing
    111. ' clear for memory
    112.  
    113. Set objOutlook = Nothing
    114. ' clear for memory
    115.  
    116. End Sub
  3. Create function to generate the body text from the table, query, whatever you're wanting to mail.
  4. Call Mail_small_Text_Outlook (or the modified mailSend), including the body generated from the 3rd step.
  5. Profit.
Oct 17 '13 #3
zmbd
5,501 Expert Mod 4TB
Corwin Moyne:

Poet has provided some nice code; however, it (IMHO) isn't usable for your application "as is" and will need some considerable modification.

However, if you can post the code that you are currently using to create and send your email, along with the information that ADezii has requested, I'm sure that we can provide some guidance/direction.

When you post your code please select the text and click on the [CODE/] formatting button to place the required [code] tags around it (that way the code is in the nice code box - (^_^) thnx) In general, any formatted (think table) or other code (such as SQL, etc...) should be formated this way.
Oct 17 '13 #4

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

Similar topics

9
by: cooldv | last post by:
i know how to replace the sign " when SUBMITTING a form in asp by this code: message = Replace(usermessage, "'", "''"). My problem is DISPLAYING data in an asp FORM, from an an access database,...
4
by: RBohannon | last post by:
I'm using Access 2000. I currently have a report being generated using the results of a query by form. The form used for this query is an unbound form, frmListDialog. frmListDialog contains...
2
by: st_moose | last post by:
I have a query that the user inputs last name of the customer and wants the output to be a specific form (that form is the form that all the information is entered originally). How do I set up the...
1
by: meganrobertson22 | last post by:
hi everybody- what is the best way to add data from one form to another? i have 2 tables: person and contract. here are some of the fields. table: person personid (autonumber and primary...
1
by: abc my vclass | last post by:
Is VS2005 debugger let me to see dataset, datatable data as table form? I found if I watch some table or dataset variable is very very hard to see. Is there any good tools or add-ins for debugger...
9
by: tomblower | last post by:
Access 2000 fully updated Three PCs manage data held on a server. They each have a front-end mdb file linked to tables on the server and on each PC. A problem has arisen over the following line...
0
by: pd123 | last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error " The name 'Peter' is...
12
by: Tom | last post by:
Hello, I have a database of employee data in access and I am trying to create a form with combo boxes for criteria (ex. gender, office, position, etc.) that let the user select criteria from...
0
by: rahul more | last post by:
My aim is - Access data from table and show it into a form's textboxes , comboxes for edition of data. I am using listview. I am selecting particular row of listview by clicking on that row and...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.