473,394 Members | 2,071 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,394 software developers and data experts.

multiple queries to multiple contacts email - vba

7
Hello everyone, need some help on figuring out.

I have a table called EmailReports table, it has:
Unit, Unitcode, POC, Emails, QueryName, and Notes

so far, i have been exporting each query and sending it out manually, i would like to automate it.

So, when a member clicks email button, i would like:

for each unit, create an email, attach the query (that is in that record) set email, and insert certain text into body (html'd) and send it....I can def review before sending or just straight up send it.


Now i have tried, macro, but issue with that is body characters are limited and i have to add SendObject macro for each query, and now exploring other alternatives.

I have tried vba, but not good enough to figure out how to run a loop and do what i want it to do...(like instead of to box, have it pull email from recordset..)

I can attach a sample of the database of what i have so far.

Any assistance is much appreciated, Im some what savy at figuring stuff out just need to see an example..and google isnt helping as much tooday...
Nov 6 '12 #1
10 3551
djsaix
7
attached docs..trying to be sneaky..cant seem to add the database..
Attached Files
File Type: docx New Microsoft Office Word Document.docx (115.8 KB, 517 views)
Nov 6 '12 #2
zmbd
5,501 Expert Mod 4TB
Djsaix:
First: as a kindness you should zip/compress your files before uploading them to any website.
Second: This is not personal; however, very few of the Experts/Mods will download your file just as a precaution. Even the most well meaning inidividual can have something lurking in their system

There are a few ways of accomplishing what you are after... MS has a page that explains one way ( docmdsendobject()) This works well for fairly straight forward reports and queries; however, there are some limitations.

Then there is the Application Automation that you can look at for some ideas.

Please post your code, remember to format it using the <CODE/> button and we'll take a look.
Nov 7 '12 #3
djsaix
7
Hey zmbd,
This computer that i am using doesnt seem to have zip (darn gov pc's).

I have tried doing doCmdsendobject(), but i am getting lost at how to properly loop it through that it sends out all my queries. I'll add in what i can, and once im hope ill zip it and add on what i have..(which isnt much sadly).

EmailReportTable (table)

Unit Unit Codes POC Emails QueryName Notes
xx1 ak SomeGuy 34@re xx1 msg1
xx2 ac SomeO 48@29 xx2 msg2

^this is what it contains(example)


main table (table)

queries (different queries that pull from main table)

button: Command65 once it clicked, here is the code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command65_Click()
  2. 'testing button on going through all records...but no success on setting up emailing for each record..
  3. 'some variables are just for testing...
  4. 'tried few other ways didnt seem to work..
  5.  
  6. Dim db As Database
  7. Dim rst As Recordset
  8. Set db = CurrentDb()
  9. Set rst = db.OpenRecordset("EmailReportsTable")
  10. Dim count As Integer
  11.  
  12. Do While Not rst.EOF
  13.  
  14. DoCmd.SendObject acSendQuery, QueryName, acFormatXLS, Emails, , , Unit, Notes, True, False
  15.     rst.MoveNext
  16.     count = count + 1
  17. Loop
  18.  
  19. MsgBox "Counting records " & count, vbDefaultButton1, "counting"
  20. 'Close what you opened.
  21. rst.Close
  22.  
  23. 'Message box for notification
  24. MsgBox "Done", vbOKOnly, "Confirmation"
  25.  
  26. End Sub
  27.  
I know its incorrect, i cant seem to figure out how to properly call each field from the table... right now its opening each email, only sending out the first record of EmailReportsTalble (with correct fields...its not moving on to the next record...grr_)
Nov 7 '12 #4
djsaix
7
still having issues..any advice?
Nov 14 '12 #5
zmbd
5,501 Expert Mod 4TB
OK,
Well... you said you were working on the project; thus, when you didn't post back I for one figured you had fixed the issues.

- Did you follow the links in #3? The MS site is fairly clear (which is unusual for them) and the automation does take a read or two to understand?

- Are the following two lines the VERY first two lines in every module and every code:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database 
  2. Option Explicit 
- Have you done a Compile of the code... you'd be surprised how many errors are fixed that way.

- Have you modified your code since posted in #4? Once compiled and any errors that show up are fixed please repost.

-
still having issues..any advice?
Please be more specific. You don't tow your car into the shop and say... it doesn't work and walk away (if you did that to some shops there would be a whole new engine and some body work, maybe new tires... brakes... $20K-US invoice) no... you try to give the shop as much information as you can.
Nov 15 '12 #6
djsaix
7
My appologies, thought I provided everything needed. The code has few minor changes, as I been playing around to get it to work..


Here is my current code:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Command65_Click()
  5. 'testing button on going through all records...but no success on setting up emailing for each record..
  6. 'some variables are just for testing...
  7. 'tried few other ways didnt seem to work..
  8.  
  9. Dim db As Database
  10. Dim rst As Recordset
  11. Set db = CurrentDb()
  12. Set rst = db.OpenRecordset("EmailReportsTable")
  13.  
  14. 'rst.MoveFirst     'this line doesnt seem to be working
  15. DoCmd.RunCommand acCmdRecordsGoToFirst
  16.  
  17. Do While Not rst.EOF
  18.  
  19.  
  20.     DoCmd.SendObject acSendQuery, QueryName, acFormatXLS, Emails, , , Unit, Notes, True
  21.     DoCmd.RunCommand acCmdRecordsGoToNext
  22.     'rst.MoveNext
  23.     'for some reason above line doesnt work but
  24.     'Docmd...GotoNext does...
  25.  
  26. Loop
  27.  
  28.  
  29. 'Close what you opened.
  30. rst.Close
  31. db.Close
  32. Set rst = Nothing
  33. Set db = Nothing
  34.  
  35. 'Message box for notification
  36. MsgBox "Done", vbOKOnly, "Confirmation"
  37.  
  38. End Sub
  39.  
I've checked out all the links you have provided, top two lines are there and this button doesnt call on any functions or modules.

Right now, their are 5 records in "EmailReportsTable", the command button pressed, it opens each record (attahces file, to block, subject, and text) all is fine, once i pres send it opens the other. So i send 5 emails with attachments (like i want) but once the last email is sent i get an error message:

Run-Time error '2498':
An Expression you entered is the wrong data type for one of the arguments.

Upon debug, it goes to line:20, identifying all the object that are called as null. So how do i get rid of the error message?
(I dont get to the msg box saying its been done)
Nov 15 '12 #7
zmbd
5,501 Expert Mod 4TB
I have an example database that will send demonstrate the send all queries by the send object and also by merging three quries into one workbook as seperate worksheets using the transferworksheet method that is then attached using automation.,. If interested let me know before 5pm-CST today otherwise it will have to wait till Monday


Regarding code in post #7:


Backup your db:

Line 9: DIM db as DAO.Database
Line 10: DIM rst as DAO.Recordset

BEFORE line 14: rst.movelast
Line 14: uncomment

Line 15: remove

Lines 17 thru 26 are wrong logic loop for code
Change
Expand|Select|Wrap|Line Numbers
  1. Do
  2. (running code)
  3. Loop until rst.eof
Line 21: remove
Line 22: uncomment


Line 14 and 22 did not work more than likely due to the incorrect database libraray. By explicitly calling DAO in lines 9 and 10 the movefirst/last/next should become available.

This is just from the few momemnts I've take to look.
Nov 15 '12 #8
djsaix
7
i think i love you..

Thank you..
Dec 14 '12 #9
zmbd
5,501 Expert Mod 4TB
You're very welcome.
How are things going with this project?
Dec 14 '12 #10
djsaix
7
The error has gone away.

And loop works both way (i changed it to yours since it made more sence.)

I sent out 40+ emails( some with 1 and others with 2-3 attachements), to over 250 people in about 5mins. YaY for automation..

Thank you.
Dec 21 '12 #11

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

Similar topics

9
by: Geoff Berrow | last post by:
This is puzzling. If I run $sql = "INSERT INTO customer (custid,username,password,title,firstname,lastname,street,towncity,postcode,telno,mobile,email,glasses) VALUES...
0
by: Urko | last post by:
Hello, I want to return multiple queries from a procedure in Oracle, I know that o can do that with REF CURSOR. But I have a problem I have a query that has a while loop and in each iteration a...
2
by: caro | last post by:
Hi I am trying to write two Select * statements to the same text file using bcp (from a stored procedure). But cannot find a way of appending to a file using bcp. Does anyone know if this...
4
by: ctoth | last post by:
I'm writing an ASP page for a project and it requires multiple queries. However, I'm trying to combine multiple SELECT statements, but can't figure out a way that actually works. Basically, here...
3
by: Gord | last post by:
I would like to create a summary report from the results of 11 queries (based on 2 tables). All the queries have the same format and return 3 numbers (Count, Current Year Bal, Last Year Bal.)...
4
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure...
8
by: beretta819 | last post by:
Ok, so I apologize in advance for the wordiness of what follows... (I am not looking for someone to make this for me, but to point me in the right direction for the steps I need to take.) I was...
7
by: vaiism | last post by:
I am creating a report that outputs the contact information and details about a water treatment plant, and needs to include information about people who work there. If I tie all the information...
4
by: Akhenaten | last post by:
I am currently using enterprise manager to run multiple queries on a single table in a DB. I refresh these queries every few minutes. Due to the huge number of them I was looking for a better way...
3
by: Brett Barry: Go Get Geek! | last post by:
Hello, I just started using Access 2007 after using Access 2003 for a long time. I've created all my queries and they work fine. However, either I forgot or it has changed but, how do I create a...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.