open a adobe file from a command button with access

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!!!
 
A

Allen Browne

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]...
 
A

Allan Murphy

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]...
 
G

Guest

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
 
A

Allen Browne

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
 
G

Guest

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.
 
A

Allen Browne

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
 
G

Guest

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
 
A

Allan Murphy

You are missing the file extension ---
try dir("C:\program Files\Modem helper\english.pdf").
 
G

Guest

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top