473,385 Members | 1,523 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,385 software developers and data experts.

Email attachment to users in final query

Hello, I'm trying to send via VBA code from access a file to each user where their emails are in the a "Final" query.

Ex: If the final query has 6 lines and user1@yahoo.com has his email account 4 times, then an email will be sent to user 1 with an attachment containing 4 lines. and also another email for user2 (user2@yahoo.com) that has 2 lines, those will be sent to him via an attached excel file

name of query Final
name offields in the FInal query: Email (contains the email of the user), name (contains the name of the user), Plant (it contains the plant where the product is manufactured) and partID (contains the product umber)

I'm not expert in access, I have been looking other trails but no able to find what I'm looking, is there some code someone can help me.. Big thanks
May 10 '17 #1
2 1037
zmbd
5,501 Expert Mod 4TB
There are a few approaches to this:

If the query has the information as you want it to appear in the excel file then the
DoCmd.SendObject (link)
May be the ticket
(You'll need to have some error handling here if you allow the user to edit the message before posting. Also, the output of the query will be very basic in nature)

If you need something more then, IMHO, you should start here with the basics of application automation, NeoPa gives an example using outlook:
home > topics > microsoft access / vba > insights > application automation

Once you have a basic understanding of this insight article we can get into the details.

(Also, there are a dozen+plus threads in the Access/VBA forum covering different aspects of how to do this... one of which could fit the bill, at the top of this page is a search box, type in "email" "query" "access" and if you want "zmbd" :) ) - even if you don't find an exact match, post back to this thread the URL for one that is closest to the goal and we'll look at what needs to be tweaked.)

-Z
May 10 '17 #2
zmbd
5,501 Expert Mod 4TB
Hello clara87:

Normally our experts do not download unrequested files usually because we work in restricted situations so let's look at what we can do in the text.

My general advice is to avoid attachments when possible.
Looking at your query, I have the impression that you have:
Expand|Select|Wrap|Line Numbers
  1. [Final]
  2. [email]          [name] [Plant]  [partID]
  3. [a@trashmail.com][Mr. A][Plant 1][Part 1]
  4. [a@trashmail.com][Mr. A][Plant 1][Part 2]
  5. [a@trashmail.com][Mr. A][Plant 1][Part 3]
  6. [b@trashmail.com][Ms. B][Plant 2][Part 1]
  7. [b@trashmail.com][Ms. B][Plant 2][Part 2]
  8. [c@trashmail.com][Dr. A][Plant 3][Part 1]
  9. (place a table in the [CODE/] format and use spaces to format columns)
> Using the word "Name" as a field name can lead to other issues, it's a reserved word
Problem names and reserved words in Access (Allen Browne)
Personally would rename that field to [CstmrName]
Also, I suspect that your database may not be normalized: (Database Normalization and Table Structures)

I am guessing that you want to send something like
Expand|Select|Wrap|Line Numbers
  1. To: a@trashmail.com
  2. Frm: clara87comany@Widgets.com
  3. Sbj: Your parts order
  4. Message: Dear Mr. A
  5. The following parts are on their way
  6. [From]    [Part]
  7. [Plant 1] [Part 1]
  8. [Plant 1] [Part 2]
  9. [Plant 1] [Part 3]
DoCmd.SendObject can do this without too much fuss without the attachment by opening a record set against your query in vba, looping through the records building your string

If you really need the attachment then you really need to understand the application automation that I linked to in the other post

in either case, you will basically do the following

Expand|Select|Wrap|Line Numbers
  1. pseudo-code
  2. open record set
  3.  check for records, if at least one record start the build
  4. read first record email
  5. start loop
  6.  read the remaining field values and add to string
  7.   ((and/or build the excel attachment))
  8.  move to next record
  9.  Read email and if different from initial email then send email
  10. Loop
  11.  (if eof send the final email)
  12. Close the record set
If you will attempt to build the code we can help you walk through it. There are several threads here dealing with opening and looping through record sets - use the search bar at the top of this page and keywords:
Access, Record set, Loop, email
See if any the returned threads are close to what you need and if so try to use and modify. If you run into issues you can post back a link to that thread and your current code (please use the [CODE\] formatting tool) so that we can work towards the goal.

Please check your Bytes.com-Inbox: I'll send you a boilerplate with what I hope are useful resources for beginning Access developers.
May 11 '17 #3

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

Similar topics

4
by: Wald | last post by:
Hello group, I've got a script here that sends emails with an attachment to an email address that is retrieved from an html form. The email sending code is include below. The problem: when...
3
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt....
1
by: abracad | last post by:
I'd like to add a form that will email a file attachment to me. Can anyone recommend a decent free script? Thanks
7
by: Susan Bricker | last post by:
I would like to generate a report (I have the report working already) using MS/ACCESS 2000 and then have the ability to send the report as an email attachment to my colleagues. I have looked...
6
by: brendan_gallagher_2001 | last post by:
Hi, Does anyone know how to create an attachment using a stream in classic ASP. I can see that it can be done in ASP.Net as per the article below: Initializes a new instance of the Attachment...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
0
by: Kirsten Kleist | last post by:
I have an application that creates several .csv files in a directory on the user's hard drive and then sends an email with the same .csv files as attachments. One of the users is getting an error...
0
by: perryche | last post by:
I have a database that users may email a certain report to each other. One of the users, all of a sudden, was not able to attached the report via email functions normally. What's happening was...
0
by: peterschedler | last post by:
How do I send an MS Word (2002) document file ( 140 MB )as a .txt email attachment and how can the recipient open it ? I am using ORANGE webmail and Mozilla Firefox .
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.