473,406 Members | 2,619 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.

Emailing Reports with a variable Query Source in VBA

Hi,

I am fairly new to Access and VBA. I have found a few threads relating to my problem, but none have led to a solution, so if I hope that I am not restating an old question...

I am writing VBA code that emails users when their license is expiring. I want the email to include a report with a summary of the data we have on file for them as an attachment.

I have a query which is the RecordSource for the User Summary Report. I have a condition on the UserID field in the query that requests a UserID input which filters the report.


I was attempting to create a query in VBA with the condition UserID = intUserID a variable Ive stored per user.

What I'm stuck on, is this... Is it possible to have a saved query say "SummaryQuery" in my database to which I can, in VBA, apply the UserID variable filter temporarily and email a Report based on that temp query? Then reset it and send a report based on the next temp query, etc? Even a pointer as to what expressions I would need to do this would be great help.

Or is there another easier way that I'm not seeing?

Thanks for your help.
Dec 18 '06 #1
2 1786
Well, I may have already solved this. I grabbed some code from the web to pull it together. But Im getting 'Run-time error '3464': Data type mismatch in criteria expression' and I'm not sure what is wrong. Here is the code:

Dim qdfNew As DAO.QueryDef
Dim strSQL As String
Dim intSLUA As Integer


strSQL = "SELECT SLUA.SLUA, SLUA.Name, SLUA.StartDate, SLUA.ExpirationDate, SLUA.FirstNotificationSent, LabContacts.LabContacts FROM (SLUA INNER JOIN PrincipleInvestigators ON SLUA.SLUA = PrincipleInvestigators.[SLUA #]) INNER JOIN LabContacts ON PrincipleInvestigators.[SLUA #] = LabContacts.[SLUA #] WHERE (((SLUA.SLUA)='" & intSLUA & "'))"


With CurrentDb

.QueryDefs.Delete ("My_Query")

Set qdfNew = .CreateQueryDef("My_Query", strSQL)
.Close
End With

strReportPath = "C:\SLUA_" & intSLUA & "_Summary.rtf"

DoCmd.OutputTo acOutputReport, "LabContacts", acFormatRTF, strReportPath

The report is named "LabContacts" and it is based on the query "My_Query"
I then attach the SLUA_###_Summary.rtf file to the email using an outlook connection. This works for me since I need to have a copy of the summary saved anyway.

Any idea why I'm getting this error? I'm using Access 2003.
Dec 18 '06 #2
MMcCarthy
14,534 Expert Mod 8TB
I assume because you called it intSLUA that it's a number. In which case you don't need the single quotes which are for text only.

Mary

Expand|Select|Wrap|Line Numbers
  1. WHERE (((SLUA.SLUA)=" & intSLUA & "))"
Dec 19 '06 #3

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

Similar topics

9
by: Brendan MAther | last post by:
I have a table called Contact_Info. I have a form that allows me to show all the contacts from a specified city and sector. Once these contacts appear on my new form I would like to be able to...
3
by: RC | last post by:
I can't quite grasp the concept of creating custom reports depending upon what options a user picks on a Form. For example, the user clicks on a "Print Reports" button and a Form pops up. On the...
3
by: tafs7 | last post by:
My code below is supposed to email me when an error occurs on the application, but it's not emailing anything. Am I missing something? I know the smtp servers I've tried work. I even added a...
4
by: BernardNem via AccessMonster.com | last post by:
Hi, I am trying to work on an employee database. The tables and fields that I am working on are listed below. I created a query because I wanted to separate the employees by department (selected...
16
by: JoeW | last post by:
I'm utilizing a database that I created within MS Access within a program I've created in VB.NET. I am using the VB front end to navigate the information, but want to be able to print a report,...
1
by: Ron | last post by:
Hi All, I needed a report so I used the report wizards to make it based on a query I made (also made with a wizard). That all works great. However, now I need a identical report only based on...
1
by: crisostomofred | last post by:
I have a report with it's source from a query. The query calls data from 3 related tables. The report is a meeting agenda and I only want to attach a snapshot report to my email based on the...
2
by: Keriana30 | last post by:
I'm using the following code in an attempt to email reports from a database form in Access. With EMsg Set .Configuration = EConf .To = Recip (variable) .CC = "Susan.Miller@ocfl.net" .From =...
8
by: marjbell | last post by:
I have a Access database of email addresses that I would like to mass email to customers. Can Access be used through Outlook? or can it just be done with Access? I know it is possible to use...
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
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
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
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.