Hello. I've been trying to create a button on my ACCESS 2007 form that will send a pdf via email of a single record. At the moment (and using code from a previous forum) I have been successful in getting the function to work; however, at the moment, the report sent contain each and every record from the form. How can I limit it to just one record? I believe the path is through my record ID key (unique to every record), but don't know how to write that into code. Can you help? Thank you in advance.
Here's the code so far: -
Private Sub xEmail_Click()
-
On Error GoTo Err_xEmail_Click
-
-
Dim stDocName As String
-
Dim stEmail As String
-
Dim stSubject As String
-
-
stDocName = "New Production Log"
-
stEmail = "email@email.com"
-
stSubject = "Production Log " & Me![Name] & ", " & Me![Date]
-
-
DoCmd.SendObject acSendForm, stDocName, acFormatPDF, stEmail, , , stSubject, , , False
-
-
Exit_xEmail_Click:
-
Exit Sub
-
-
Err_xEmail_Click:
-
MsgBox Err.Description
-
Resume Exit_xEmail_Click
-
-
End Sub
-
8 12724
Thanks, zmbd. You mean to change the sendobject to, say, a query or report where I have the criteria I need?
However, is there a way to update the current code to have criteria in place that it would only send a form of the current record, as identified by the individual record ID?
zmbd 5,501
Expert Mod 4TB
the send object is just that... you're sending the entire object; thus, in a query, set the conditions to return the record(s) of interest.
I've not used a parameter based query with this method... might work... I usually have a generic query that I delete and re-create via vba. I have a thread here with an example along those lines... should be an easy search...
Well, here's what I've tried. Yet I can't get it to recognize the specific ID. Should I be using sendobject at all? It's the only function that appears to work with this specific code.
I'm very much a newbie, so pardon my ignorance if everything I've done makes no sense. - Private Sub xEmail_Click()
-
On Error GoTo Err_xEmail_Click
-
-
Dim stDocName As String
-
Dim strDocName As String
-
Dim stWhere As String
-
Dim stEmail As String
-
Dim stSubject As String
-
-
If Me.Dirty Then Me.Dirty = False
-
-
stDocName = "New Production Log"
-
strWhere = "[ID]=" & Me!ID
-
stEmail = "email@email.com"
-
stSubject = "Production Log " & Me![Specialist Name] & ", " & Me![Reporting Week]
-
-
DoCmd.SendObject acSendForm, stDocName, acFormatPDF, stEmail, , , stSubject, , , False
-
-
Exit_xEmail_Click:
-
Exit Sub
-
-
Err_xEmail_Click:
-
MsgBox Err.Description
-
Resume Exit_xEmail_Click
zmbd 5,501
Expert Mod 4TB
OK,
I think you're going to have to use the workaround method similuar to what I've done with the transferworksheet method. Alot of the send-this and transfer-that methods in access require a "final" resolved object.
What I do in the workaround is check for the exsistance of my generic query, delete it if it exsists, and then re-create the query. I then use this as the object.
You do this using the querydef collection....
I just posted code to do something like this within the last few weeks I'll post the the thead link here in a little while (have to find it :) )if you don't find it thru a search first.
Busy day.
That would be fantastic. I did look around for the "querydef" but was unable to find the exact post you were referring to. I see now that there is no way to limit criteria on the SendObject, so your idea of creating a query with the current record ID-specific parameter sounds like a good bet. Thanks.
zmbd 5,501
Expert Mod 4TB
Well, that is very annoying... I can't seem to find it either and I posted it around the 9/17ish... who knows.
Here's are the basic concepts... (I haven't debugged this and it's from memory): - Dim zdb As Database
-
Dim zSQL As String
-
Dim zQueryName As String
-
Dim zqryDef As QueryDef
-
Dim z_txtboxval As String
-
'
-
'Set initial error trap
-
On Error GoTo Z_Errtrap
-
'
-
'set variable values
-
Set zdb = CurrentDb
-
zQueryName = "qry_CHANGETHISNAME"
-
'Delete old query first - we want fresh data!
-
'(if the query doesn't exsist, this will toss error: 3265
-
dbs.QueryDefs.Delete strQueryName
-
'
-
'Build the SQL.
-
zSQL = "SELECT field1, field2, field3 " _
-
& "FROM TABLEorQRYofINTEREST" _
-
& "WHERE (((Field3)='" & z_txtboxval & "'));"
-
'
-
'Create query definition
-
Set zqryDef = dbs.CreateQueryDef(zQueryName, zSQL)
-
'
-
'More VBA Here
-
'...
-
' *** End of Code ***
-
'>>>
-
'
-
Exit_Click:
-
Set zdb = Nothing
-
Exit Sub
-
'
-
Z_Errtrap:
-
If err.number = 3265 then
-
resume next
-
else
-
Msgbox Err.Number & " - " & Err.Description
-
Resume Exit_Click
-
end if
-
End Sub
zmbd 5,501
Expert Mod 4TB
!Updated!
At the time of this thread the TempVars Object (Access) collection had just been added to Access2007; however, not much was known about it at the time; however, this thread has popped back up in my message que; thus, an update.
Create your stored query such that it uses the Tempvars collection for the Where Clause: - SELECT field1, field2, field3
-
FROM TABLEorQRYofINTEREST
-
WHERE (((Field3)= tempvars![ValueFromForm] ));
Then the VBA code in Post #8 would change to - Dim zdb As Database
-
Dim z_txtboxval As String
-
'
-
'Set initial error trap
-
On Error GoTo Z_Errtrap
-
'
-
'tempvars will not take an object so a workaround
-
ztextboxval = Me!ID
-
'
-
'set tempvar values
-
if (tempvars![ValueFromForm] & "") = "" Then
-
tempvars.Add "ValueFromForm",ztextboxval
-
else
-
tempvars![ValueFromForm] = ztextboxval
-
end if
-
'
-
'you can then do something like this:
-
DoCmd.SendObject _
-
objecttype:=acSendQuery, _
-
objectname:="QryForEmail_Example", _
-
OutputFormat:=acFormatPDF, _
-
To:="z@z.z", _
-
Subject:="Requested Query Results", _
-
MesageText:="The results from your latest data request are attached"
-
-
'...
-
' *** End of Code ***
-
'>>>
-
'
-
Exit_Click:
-
-
Exit Sub
-
'
-
Z_Errtrap:
-
If err.number = 2501 then
-
'the email sent was canceled by the user
-
resume next
-
else
-
Msgbox Err.Number & " - " & Err.Description
-
Resume Exit_Click
-
end if
-
End Sub
I've been using a variation on this for quite awhile now for simple report emails and it saves on the database bloating that would happen with the previous workaround.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Danny J. Lesandrini |
last post by:
Our orders database exists inside our firewall but we have a web site hosted
on an ISP server. If we wanted to give users the ability to query the
status of their order in real time, we could just...
|
by: Stewart Graefner |
last post by:
I have been unable to locate anywhere the answer to my problem. I
would like to be able to download/import a single record. This record
is stored in many different related (one to one) tables. I...
|
by: Peter Morris [Droopy Eyes Software] |
last post by:
Hi all
When I bind to multiple records I use a DataList. This allows the
web-designer to add code like <%#DataBinder.Eval(Container.DataItem,
"Name")%>
Whenever I want to retrieve a single...
|
by: Khamal |
last post by:
Hi..
I need to diplay a single record from mysqldb..'
i just create the dataset...
-----------------------
myConnectionString = "Database=altia;Data Source=development;User...
|
by: Andy |
last post by:
Hi All.
I'm working for a company that has set out a guideline for retrieving
data from a database. Nobody can explain to me the reason for the
following.
When retrieving a set of records...
|
by: zoro |
last post by:
Hi, I am looking for the recommended way to retrieve several values
from a single record, i.e. a typical lookup scenario. An example would
be a query that needs to retrieve user_name, user_addres,...
|
by: RayPower |
last post by:
I'm having problem with using DAO recordset to append record into a
table and subsequent code to update other tables in a transaction. The
MDB is Access 2000 with the latest service pack of JET 4....
|
by: ApexData |
last post by:
When I use Dlookup. I am only able to return a single value and
therefore cannot seem to assign a single records (3-field values) to
(3-Variables). I noticed that I can get the 3-field values, but...
|
by: Aussie Rules |
last post by:
Hi,
In all my coding to date, i have been dealing with multiple results in my
dataset, looping through them with
SqlDataAdapterContactProfile.Fill(contact, "Profile")
For Each pRow In...
|
by: AmateurDBer |
last post by:
Hello, I'm looking for Allen.
I hate to bother you again, but I am now trying to e-mail the single
record from the same form mentioned before (using a macro button) (reference
thread about...
|
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,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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: 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...
|
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,...
|
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...
|
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,...
|
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...
| |