Re: Linking pdf files
- From: "Arvin Meyer [MVP]" <a@xxxxx>
- Date: Fri, 21 Sep 2007 07:31:22 -0400
OK.
FileExists is a Public function that goes into a standard module, If you put
it in a form module, it can only be used when that form is open. If you put
it in a standard module, it is much easier to use. I also just noticed my
code has a slight error, which is easily fixed.
So now lets look at this code and see what it says:
strFileSpec is a variable which takes the the of the file, so if you used
the Immediate Window to debug your code and entered:
?FileExists("C:\Windows\win.ini")
and hit the Enter key, the answer you'd get back would be: True
The code in the form event for a command button named: cmdHyperlink
should look like:
Private Sub cmdHyperlink_Click()
Dim strPath As String
strPath = Me.txtBoxName
If Not IsNull(strPath) Then
If FileExists(strPath) = True
Me.cmdHyperlink.HyperlinkAddress = strPath
Else
MsgBox "File not found", vbOKOnly, "No PDF"
End If
End If
End Sub
strPath is the path to the file and in this case will have the same value as
strFileSpec, and that value is the path: C:\Windows\win.ini, or in your case
the PDF file path on your hard drive or the server. So now, when you click
the button, it checks first is there a value to check in the textbox:
If Not IsNull(strPath) Then
If that's true, does the file's path in the text box actually exist?
If FileExists(strPath) = True
Now if it does, open it using that path as a hyperlink (note: hyperlinks are
merely a path with special properties, so just by calling the path a
hyperlink address, VBA (the code language) will treat it that way and open
the file associated with that file type and path.
If it doesn't exist, tell the use by showing a message box that says "File
not found"
Make sense now?
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
"Tammy" <Tammy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C676B6F1-0818-4212-B9E5-A326344F2778@xxxxxxxxxxxxxxxx
Thanks for the reply, I tried to understand your suggestion, but couldn't.
Not because it didn't make sense -- I'm sure it does; but, because I do
not
know code at all. I cut and paste it into a sample form, but I wasn't
sure
if I needed to edit the code. I'm sorry.
"Arvin Meyer [MVP]" wrote:
How about this? Add the following function to a standard module:
Public Function FileExists(strFileSpec As String) As Boolean
Dim intFileLength As Integer
On Error Resume Next
intFileLength = FileLen(strFileSpec)
If Err = 53 Then
FileExists = False
Else
FileExists = True
End If
End Function
Now use it to check whether the file exists before you open it. Use a
command button to follow the hyperlink:
Private Sub cmdHyperlink_Click()
Dim strPath As String
If Not IsNull(Me.txtBoxName) Then
If FileExists() = True
strPath = Me.txtBoxName
Me.cmdHyperlink.HyperlinkAddress = strPath
Else
MsgBox "File not found", vbOKOnly, "No PDF"
End If
End If
End Sub
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
"Tammy" <Tammy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:679CCC11-A550-4B2D-B1D7-2CE4D13C236A@xxxxxxxxxxxxxxxx
I have a table with about 12,000 records. Each record has a hyperlink
set
up
to a path where pdf files reside -- although each record has the
hyperlink
path set up, there isn't an actual pdf file for every single record --
eventually there will be. Right now, the user can see the link, but
has
no
idea if a file actually exists or not. He can figure it out once he
clicks
on the link and the pdf file does not show up. However, I would like
the
form to show him somehow if there is a pdf file for that particular
file
or
not -- without manually going in and setting a field separate to
"yes/no."
I
thought I could perhaps set up a bmp file that says "No PDF file
Available,"
which would show up if there is no pdf file in the physical location of
the
path. But, I am at a loss on how to do it. Any help at all would be
greatly appreciated. I do not know Visual Basic, but can cut and paste
code
if given enough instruction. Thanks so much!
.
- Follow-Ups:
- Re: Linking pdf files
- From: Tammy
- Re: Linking pdf files
- References:
- Re: Linking pdf files
- From: Arvin Meyer [MVP]
- Re: Linking pdf files
- From: Tammy
- Re: Linking pdf files
- Prev by Date: Re: Vista & Office Bug.
- Next by Date: Re: Searching for and editing a record in form view
- Previous by thread: Re: Linking pdf files
- Next by thread: Re: Linking pdf files
- Index(es):