473,799 Members | 3,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Print Access 2007 Attachment with VBA

31 New Member
Hi,

I dont even know where to start on this one. I found this on the net (everything in italics are the authors comments):

Expand|Select|Wrap|Line Numbers
  1. Public Function OpenFirstAttachmentAsTempFile(ByRef rstCurrent As DAO.Recordset, ByVal strFieldName As String) As String 
  2.  
  3.     Dim rstChild As DAO.Recordset2
  4.     Dim fldAttach As DAO.Field2
  5.     Dim strFilePath As String
  6.     Dim strTempDir As String
  7.  
  8.     strTempDir = Environ("Temp") ' Get the Temp directory from the environment variable.
  9.     If Right(strTempDir, 1) <> "\" Then strTempDir = strTempDir & "\" ' Make sure the path always ends with a backslash.
  10.         Set rstChild = rstCurrent.Fields(strFieldName).Value ' the .Value for a complex field returns the underlying recordset.
  11.         strFilePath = strTempDir & rstChild.Fields("FileName").Value ' Append the name of the first (and only) attached file to temp dir.
  12.         If Dir(strFilePath) <> "" Then ' the file already exists--delete it first.
  13.         VBA.SetAttr strFilePath, vbNormal ' remove any file attributes (e.g. read-only) that would block the kill command.
  14.         VBA.Kill strFilePath ' delete the file.
  15.     End If
  16.  
  17.     Set fldAttach = rstChild.Fields("FileData") ' The binary data of the file.
  18.     fldAttach.SaveToFile strFilePath
  19.     rstChild.Close ' cleanup
  20.     VBA.Shell "Explorer.exe " & Chr(34) & strFilePath & Chr(34), vbNormalFocus ' Use Windows Explorer to launch  the file.
  21.  
  22. End Function 'OpenFirstAttachmentAsTempFile
  23.  

Then I wrote this function just to test it in a database that has a Table1 with an Attachment field named "Files" in which I had already placed a file:
Expand|Select|Wrap|Line Numbers
  1. Public Function TestOpenFirstAttachmentAsTempFile()
  2.     Dim dbs As DAO.Database
  3.     Dim rst As DAO.Recordset
  4.  
  5.     Const strTable = "Table1"
  6.     Const strField = "Files" ' Attachment field in Table1
  7.  
  8.     Set dbs = CurrentDb
  9.     Set rst = dbs.OpenRecordset(strTable)
  10.     'rst.MoveNext ' Uncomment this line to go to the 2nd row in the Table.
  11.     OpenFirstAttachmentAsTempFile rst, strField
  12.     rst.Close
  13. End Function 
  14.  
By using the VBA.Shell command with Explorer.exe, the file will be opened just as if you double clicked it from Windows Explorer!

But i would like to take it one step farther and print it with the default printer. Does anybody think that is possible, or even worth doing. Basically i have documents attached (PDF documents), and want them to print out as the last 2 pages of a report (actually printed to a pdf document, if that helps at all).

Again, as i always say "Any help is greatly appreciated".
Feb 19 '09 #1
2 9481
PianoMan64
374 Recognized Expert Contributor
@crazyhouse

Hey crasyhouse,

I found this link about being able to print batches of PDF files from OLE or DDE.

See if this will help?

http://support.adobe.com/devsup/devs...docs/51412.htm

Thanks,

Joe P.
Feb 19 '09 #2
Worsty
1 New Member
I was wondering if anyone had an answer for this. I can run the code in this post and it works great to open assigned attachments from the table (pdf), but what i want to do also is:

First run the access reports, then either save these Access reports as a pdf or open the pdf attachments per record and create one document as a pdf. Can anyone help me out on this? Thanks so much!
Jul 2 '09 #3

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

Similar topics

37
5268
by: jasmith | last post by:
How will Access fair in a year? Two years? .... The new version of Access seems to service non programmers as a wizard interface to quickly create databases via a fancy wizard. Furthermore, why would you even continue to use Access as a backend when you have a much superior option in SQL express? What about as a future front-end development tool? Let's get serious. Microsoft continues to publish numerous articles and videos on how you...
4
7722
by: VoodooFrog | last post by:
I am trying to run the following code as a simple test of adding an attachment through access 2007: Dim rsJob As DAO.Recordset2 Dim rsChild As DAO.Recordset2 Dim field As Field2 Set rsJob = Me.Recordset Set rsChild = rsJob.Fields("attachments").Value Set field = rsChild.Fields("filedata")
1
3467
by: bloukopkoggelmander | last post by:
Hi all I have a bit of a strange problem where I want to set a table field in Access 2007 to an attachment field, but when I follow the Microsoft workmethod, I get no option in Access for attachment. It should be there, but hey, it's not! Here is the workmethod I am following : http://office.microsoft.com/en-us/access/HA012138521033.aspx?pid=CH100728901033 Does anyone have this same problem, or does anyone know why I might not have...
2
2604
by: nduerr | last post by:
I have a table with pdf files stored in an attachment data type field in a 2007 Access File. I would like to run a query that would select a group out of this table (easy part) then send the pdf file stored in the attachment field in each of the selected records to a specific e- mail address as an attachment to the e-mail. The pdf files can be zipped together or left separately. First off, Is this possible? I haven't found a lot of...
1
2521
by: amrit1123 | last post by:
I m working on ms access 2007. and i want to create a table which have a field of datatype attachment through query u .like this (create table tablename (name varchar);). so, how to create a table using query which have a field attachments. so please help me which keywords(datatype) i used to create attachment datatype in a table like we use varchar to create character type field. or How to create a attachments field in access table...
0
1262
by: ProgrammerChicago | last post by:
Is there any way to upload and download files using the Access 2007 attachment field type in an ASP.NET webpage? I found this article pertaining to SQL Server 2005 (http://aspnet. 4guysfromrolla.com/articles/120606-1.aspx), but it's a little complex for me, and it might be better to have some documenting the procedure with Access -- that is, if it is at all possible.
10
9125
by: Snoopy33 | last post by:
I have a DB that I developed on access XP (2002) and deployed over a year ago. No one has had problems printing any of the reports within the DB until we started loading 2007 on new computers. The access 2007 users cannot print one of the reports. This is maddening since I cannot duplicate the issue on any computer that runs 2003 or below. Is there something going on that I'm not seeing? Does anyone have any suggestions at all on...
5
3194
by: mturner64 | last post by:
I am developing an application using asp.net where a user can enter first name, last name, donation amount, date, et cetera. After the user enters the information and clicks submit, the information is written/stored into an Access 2007 database, which works well. I am now wanting to allow a user to upload an image of themselves along with their text information and have that image stored in a field of the Access 2007 database. I have...
0
2741
by: bkberg05 | last post by:
Hi - I currently use Access 2003 and have documents stored in an OLE data type field. I want be able to write a query that contains various other data elements from the table plus the OLE field and export these to an excel file. The query itself shows the document in the OLE field, but when I export the spreadsheet to Excel, the field holding the document shows up blank. Doing research, I saw Access 2007 had a different data type called...
0
10485
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.