open a adobe file from a command button with access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 4/5 thousand adobe files in a directory, after selecting the one I
want from a combo box I want to click a command button that says "View
Document". Each document has its own number, 0001, 0002, 3435... What I
don't know how to do is write the code to open adobe and direct it to the
directory and the number. I think this is for an advanced coder (not me) but
I would like some help, please!!!
 
You can use FollowHyperlink to open the document in the program registered
to handle that type.

This is an example of the event procedure (code) to use. It assumes the
combo named MyCombo contains the number, and you need to add the path name
and the .pdf extension.

Private Sub OpenDoc_Click()
Dim strDoc as String
If Not IsNull(Me.MyCombo) Then
strDoc = "C:\MyFolder\" & Me.MyCombo & ".pdf"
FollowHyperlink strDoc
End Sub
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

"open a adobe file from a command button" <open a adobe file from a command
button @discussions.microsoft.com> wrote in message
news:[email protected]...
 
Another option to allen's solution is

Coding that I use to open an user's guide in a pdf format

Sub user_guide_general()
' short guide for general users
Dim app_name As String

app_name = "c:\program files\adobe\acrobat 5.0\reader\acrord32.exe
j:\common\databases\general guide.pdf"

Call Shell(app_name, 1)

End Sub

"c:\program files\adobe\acrobat 5.0\reader\acrord32.exe is where the
acrobat reader exe file resides

j:\common\databases\general guide.pdf is the location of the PDF file.

--
Allan Murphy
Email: (e-mail address removed)
"open a adobe file from a command button" <open a adobe file from a command
button @discussions.microsoft.com> wrote in message
news:[email protected]...
 
Allen, Hi. Thanks for the help with my problem. I am over my head in what
I’m trying to do because after entering your code I get an error on
“hyperlink followâ€. Because I’m in over my head I decided to send you what I
did in hopes you can help me fix this.

Private Sub Command10_Click()
Dim xx As String
Dim strDoc As String
xx = Me.VaultNo
MsgBox "No is " & xx

If Not IsNull(Me.Command10) Then
strDoc = "E:\Access\Temp\" & Me.VaultNo & ".pdf"
FollowHyperlink strDoc
End If

MsgBox "Str= " & strDoc
End Sub

Each document has a number, 1-3678. Each document has a name. I use the
combo box to let the person select by title, the document they want to see.
I store the number of that document in xx. I added your code and then added
a message box to see if I was getting the correct name of the document in
E:\access\temp. I am, but it errors out on followhyperlink strdoc and my
understanding of VBA is only 1 course deep. I should have played with
something easy!!!

Thanks
 
The idea looks right, except you need to test if the VaultNo text box is
null, not if the command button is.

What error message do you receive?
If 490, the name might be incorrect.
Do you need to use Format() to add leading zeros to the name?

Does Dir(strDoc) return the right name, or a blank (indicating that the
document does not exist)?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

"open a adobe file from a command button"
message
 
Hi Allen. I was testing for "VaultNo', that did not work so I put in the
command button (I'm reaching now). It is a '490' error but I'm getting back
expected results. VaultNo = 1, strDoc returns "E:\Access\Temp\1.pdf, but the
error says "cannot open this file. I have Adobe on my box and the file opens
correctly when I go to the directory and click on it.
 
Open the Immediate window (Ctrl+G)

Type:
Dir("E:\Access\Temp\1.pdf")
and press enter.

If you get no response, the file name is not correct.
If you do get a response (the file name), then try this in the Immediate
window:
FollowHyperlink "E:\Access\Temp\1.pdf"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

"open a adobe file from a command button"
message
 
Allen, Hi. I put it in exactly as you said and I got nothing. I entered
dir("C:\program Files\Modem helper\english"). I got nothing here also, yet
this document is in this directory
 
You are missing the file extension ---
try dir("C:\program Files\Modem helper\english.pdf").
 
Allan, Hi. Wanted to thank you very much for leading me in the right
direction. As I continue in Access I will be posting more questions so
please feel free to respond! Here is the solution.

Dim strdoc As String
On Error GoTo errorhandler

if Not IsNull(Me.[Vault No]) then
strdoc = "F:\common\Offsites\Images\"&Me.[Vault No].Value & ".pdf"
FollowHyperlink strdoc
End If

errorhandler:
MsgBox "No Document"
 
Back
Top