Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 7th, 2012, 11:09 AM
nearpost nearpost is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 nearpost User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 51 sec
Reputation Power: 0
Open attachment through VBA

I have a table with an attachment field. The attachments are all pdf files. I am looking for a way to open one of the attachments through VBA by creating a recordset of the attachments, locating a specific file name, then opening the pdf. I have the first two parts done, and can successfully locate the pdf file name, I just can't find a way to open it.

So again, this is NOT an attachment in an Outlook email, and not a saved file; it is a pdf stored in an attachment field. I want to simulate the same thing as opening an attachment window in Access, navigating to the file name in the list, then either double-clicking it or clicking Open.

When the pdf is originally saved I want to capture the name in a log so I can reference it later (for instance MyJulyFile.pdf), then later save additional files in the attachemt field (MyAugFile.pdf, MySeptFile.pdf, etc), then go back and select the specific file name in my log, and have the code go to the table with the attachments, find it and open it.

Here is my code so far:

Sub OpenAttachment(ByRef rstCurrent As DAO.Recordset, ByVal FieldName As String, ByVal AttachmentName As String)
'This procedure will open an existing attachment already stored in an attachment field.

Dim rstChild As DAO.Recordset2

Set rstChild = rstCurrent.Fields(FieldName).Value ' the .Value for a complex field returns the underlying Recordset.
rstChild.MoveFirst

Do Until rstChild.EOF
If rstChild.Fields("FileName").Value = AttachmentName Then
MsgBox "Match found" 'The code to open the attachment would go here
Exit Do
Else
rstChild.MoveNext
End If
Loop

End Sub

1. Through a command button click event I create the recordset of the parent table that has the attachment field in it, then call the above sub and pass the recordset as the first argument, then pass the name of the attachment field as the second, then the name of the .pdf file as the third argument.

2. The code above then creates the rstChild recordset from the attachment field, iterates through the recordset and locates the matching name.

That all works fine so far. I just can't find the way to do the last step and open the pdf once the recordset cursor lands on it.

Any suggestions will be much appreciated.
Thanks

Reply With Quote
  #2  
Old November 7th, 2012, 04:01 PM
June7's Avatar
June7 June7 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Location: The Great Land
Posts: 256 June7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 9 h 29 m 29 sec
Reputation Power: 5
PDF can be opened only in Adobe software. I think you have to:

1. save the attachment pdf out to a folder
http://blogs.office.com/b/microsoft...ccess-2007.aspx

2. use hyperlink code to open file
http://allenbrowne.com/func-GoHyperlink.html

3. delete the pdf from folder
http://stackoverflow.com/questions/...g-a-file-in-vba
__________________
I like to know if my suggestion helped you. One way to let me know is by clicking scales at top right corner of post.
Debug!Debug!Debug!http://www.cpearson.com/excel/debug.htm

Reply With Quote
  #3  
Old November 8th, 2012, 07:37 AM
nearpost nearpost is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 nearpost User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 51 sec
Reputation Power: 0
June7 - I appreciate the reply.

Yes I know that i can copy the attachment out to a temp folder to open it. What I am trying to do though is NOT have to do that, but rather simulate the same thing as opening the attachment window by (for instance) double-clicking the paper clip in the attachment field in the table, then either double-clicking or highlighting the specific attachment name and clicking Open. When done that way, Access does not copy the pdf out to a temp folder and open it there, it just opens it. I'm trying to find to way through code to reproduce this funtionality of just straight opening the attachment.

Reply With Quote
  #4  
Old November 8th, 2012, 05:05 PM
June7's Avatar
June7 June7 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Location: The Great Land
Posts: 256 June7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 9 h 29 m 29 sec
Reputation Power: 5
Actually I think the Open action from the Attachments dialog does save the document to a temp location then opens that file. This is supported by a check of the file properties in the Adobe app with the Attachment file opened from the dialog and seeing the Location '...\Temporary Internet Files\ACCDDxx\'

Although when I try to navigate to that folder with Windows Explorer, can't find it. I click on the displayed path in the Adobe properties and an Explorer window opens. Bizarre - some sort of 'virtual' folder?

Regardless, to replicate this behavior will have to save the attachment to a folder location then open the saved file. All code snippets I can find follow this.

Last edited by June7 : November 8th, 2012 at 05:25 PM.

Reply With Quote
  #5  
Old November 9th, 2012, 11:18 AM
nearpost nearpost is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 nearpost User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 51 sec
Reputation Power: 0
Yes, all of the code examples I have found are also creating a "temp copy" of the attachemnt. If possible I am trying to avoid have a bunch of copies pile up when I already have the pdf files saved in my attachment field. And yes I know there is code I could use to turn around and delete the temp copy, but that all seems unnecessary as my thinking is there still should be a way to just straight open the file. I can do it through the Attachments dialog, but again after creating the recordset and landing on the correct file name in the recordset. I just haven't found the method or technique for opening.

I looked, and Access actually doesn't create any kind of "temp copy" when you open an attachment through the Attachments dialog, it just opens the file. I am still hoping to find a way to do this through code.

Thanks again for the replies.

Reply With Quote
  #6  
Old November 9th, 2012, 04:06 PM
June7's Avatar
June7 June7 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Location: The Great Land
Posts: 256 June7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 9 h 29 m 29 sec
Reputation Power: 5
I still say Access is saving a 'temp' copy of the attachment somewhere, even if it is 'virtual' and not on disk, and Adobe renders that file.

I can only suggest you implement the known code at this time and if you find alternative solution later, implement it. Look forward to seeing it.

Reply With Quote
  #7  
Old November 12th, 2012, 01:33 AM
keekerriy keekerriy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 6 keekerriy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 56 sec
Reputation Power: 0
I would be a little suspect of a conclusion based on only one study and not confirmed by other research.




Reply With Quote
  #8  
Old November 12th, 2012, 04:11 AM
ericagodwin ericagodwin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 ericagodwin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 24 sec
Reputation Power: 0
I'm trying to find to way through code to reproduce this funtionality of justURLURLURLURL

Reply With Quote
  #9  
Old December 15th, 2012, 05:19 AM
robinmbers robinmbers is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 robinmbers User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 46 sec
Reputation Power: 0
yeah,i think so.Actually I think the Open action from the Attachments dialog does save the document to a temp location then opens that file.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Open attachment through VBA


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap