473,503 Members | 1,858 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 9453
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
5179
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...
4
7698
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 ...
1
3451
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...
2
2587
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...
1
2502
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...
0
1246
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....
10
9096
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. ...
5
3155
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...
0
2731
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...
0
7202
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
7280
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
7330
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
7460
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...
1
5014
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...
0
4672
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...
0
3167
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...
0
1512
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 ...
1
736
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.