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

Filter Access Report to Email, Relevant Records Only

4
Microsoft Access 2007.

Background: I have a query that received work orders from out client system and runs them through access. Once in Access, an employee goes through the query output and organizes the records (mentally) by product_code. There can be be 1 or more records of a certain product_code and there are 129 total different product_codes. Say, a typical time the employee runs this query they might see 25 different records consisting of 6 different product_codes.

Each product_code designates who (an email address) should be sent the work orders to approve. The employee currently copy/paste the relevant records in an Outlook 2010 email body and uses an external excel sheet with the email addresses to see who it should be sent to. I'm automating this whole process.

I've gotten an email to generate in vba, and to send an 1 email to each person who has one of their product_codes in the query output. My problem is that I'm having trouble figuring out how to filter the emails so that instead of seeing all 25 records (from above example) they only see the records with their product_code.

Another thing to mention is that as of now, I have a script that converts the report to HTML and sticks it in the body of the email. So I'm not sure how to edit that script to allow to filter the report or if that's even where I need to do the filtering (another procedure maybe?)

Any advice would be greatly appreciated; ahh that feeling when a project's winding down ;-)

This is my html conversion script:


Expand|Select|Wrap|Line Numbers
  1. 'product_code = Mfg_Cd in this script
  2.  
  3. Function exporthtml(str_Sender As String, str_DataMsg As String)
  4.  
  5. Dim strlin As String, strHTML As String
  6. Dim objOutlook As Outlook.Application
  7. Dim objOutlookMsg As Outlook.MailItem
  8. Dim objOutlookRecip As Outlook.Recipient
  9. Dim varX As Variant
  10. Dim RS As Recordset
  11.  
  12.   Set RS = Me.Recordset
  13.  
  14.   Set objOutlook = Outlook.Application
  15.   Set objOutlookMsg = Outlook.Application.CreateItem(olMailItem)
  16.  
  17.   DoCmd.OutputTo acOutputReport, "Report-q_Workflow", acFormatHTML, "filepath"
  18.  
  19.   Open "filepath" For Input As 1
  20.   Do While Not EOF(1)
  21.   Input #1, strline
  22.     strHTML = strHTML & strline
  23.   Loop
  24.   Close 1
  25.   If Left(objOutlook.Version, 2) = "10" Then
  26.     objOutlookMsg.BodyFormat = olFormatHTML
  27.   End If
  28.  'strHTML is how I stick the html conversion in the body if anyone is wondering 
  29.  objOutlookMsg.HTMLBody = "Hi Team,<br>Please let me know if the following orders are okay to approve." & vbCrLf & vbCrLf & strHTML & "<br>Thank You" & vbCrLf & vbCrLf 
  30.  
  31.       With objOutlookMsg
  32.       Do
  33.  
  34.       Set objOutlookRecip = .Recipients.Add(str_Sender)
  35.       objOutlookRecip.Type = olTo
  36.       Loop Until RS.EOF
  37.       Close
  38.       Set objOutlookRecip = .Recipients.Add("")
  39.       objOutlookRecip.Type = olCC
  40.       objExport = exporthtml
  41.       .Subject = "International Authorization"
  42.       .Importance = olImportanceHigh
  43.       For Each objOutlookRecip In .Recipients
  44.          objOutlookRecip.Resolve
  45.       If Not objOutlookRecip.Resolve Then
  46.          objOutlookMsg.Display
  47.       End If
  48.       Next
  49.       .Send
  50.       End With
  51.  
  52. End Function
  53.  
Jun 24 '12 #1
1 4393
twinnyfo
3,653 Expert Mod 2GB
axkoam,

I can't go through and write all the code for you, but I have a very similar function in one of my databases. I will outline how I would do it, and then you can play with the code to find out how it will work for you.

1. First, I would establish a global variable like current_product_code, which will hold the product_code for which you want to send the report.

2. When you want to send these reports, you need to find out which product_codes will be contained in the current set of reports. Build an aggregate query that lists all the product_codesfor the current list of reports, i.e. even if a product_code is found twice, it should only show up on the query once. In your code, create a recordset based on that query--this will be the outer loop of your e-mail code. You will set your global variable current_product_code to the first item in this recordset.

3. You should re-configure your report to have as its RecordSource a query that lists all the orders limited by the current_product_code. When you do this, because of step 2 above your report will have only those records that apply, instead of all available records.

4. Now that you know the current_product_code, you also know who should receive the work orders. Establish the E-mail body text, using variables, concatenation and other methods to build an e-mail note to the approval authority. Use the DoCmd.SendObject method, sending your newly configured report as an attachment (there are various options), to the e-mail address designated.

5. Now, loop back to the next product_code in your recordset, setting your global variable again, and repeat.

Again, this is just the basic outline, but I'd be glad to work through this as you build your code. It took me a while to perfect this process, but works like a charm with multiple types of reports that I generate.

Let me know if you need more help!
Jul 25 '12 #2

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

Similar topics

2
by: Vikrant | last post by:
Hey Friends I need to export an Access Report using a filter. I am using the method OutputTo m_pDoCmd->OutputTo( 3, // asOutputReport COleVariant(strReportName), // <report name>...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
0
by: access03 | last post by:
Hello, this is my question -- I need to create a multi-page report. each page is about a product selected during runtime. the number of products is also decided at runtime. right now, i...
2
by: Pradeep Varma | last post by:
Hi, I am using Acrobat 6.0. I am trying to save an Access report to a PDF file using the Acrobat Distiller but came across an error message “ActiveX component cannot create object –429”. I have...
1
by: JRNewKid | last post by:
I have an Access report. In the source table of data I have a check box, dlyBillCode, which is checked if I want that record to be included in the report. That dlyBillCode itself doesn't appear...
1
by: sonicfun2006 | last post by:
I have SQL Server Database and MS Access 2003 is connected with ODBC. I have very large amount of records in various tables. The database is very dynamic as it changes every minute. I’m trying to...
1
by: dfw1417 | last post by:
I have used a query and report filter to return records related to a specific account id. I want to print a report including only the latest 6 records out of the set returned by the record filter. I...
4
by: Fran | last post by:
I recently tried to use code for "Use a multi-select list box to filter a report" from Allen Browne in my database. I was able to add the code and adapt it to my needs, however I am getting an...
2
by: harley.mcnerthney | last post by:
I have an Access 2007 problem and I would just like to know if there is some sort of solution out there. The problem is, when I build a report that will 99% of the time be one page or less maybe...
3
by: Gord | last post by:
I'm trying to filter a report with a date in VB code. If I type an actual date bracketed with the pound symbol (i.e. #3-Jul-08#) I can get the filter to work. I can't seem to get it to work by...
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...
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
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
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
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
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.