Make a Unique Document Correspond to every Primary Key Number

Bill Bisco

Custom User Title
Local time
Today, 17:00
Joined
Mar 27, 2009
Messages
92
Dear all,

In my database, I am typing in the information present on a scanned pdf on my computer. However, I would like to create a command button that will open the pdf corresponding to my Primary Key. So basically, if I was on Record # 23, I would open up a PDF in my directory entitled "23."

Any help is greatly appreciated,

Bill
 
In the Click event of your command button, something like the following (I have included error handling here in case no file is found). You'll need to modify the path name accordingly;

Code:
Private Sub cmdYourButton_Click()
On Error GoTo HandleError
 
    Dim strPath As String
    
    strPath = "C:\Documents and Settings\UserName\My Documents\" & Me!RecordID & ".pdf"
    
    Application.FollowHyperlink strPath
        
Exit_Here:

    Exit Sub
 
HandleError:

    If Err.Number = 490 Then 'No file was found
        MsgBox "No associated document was found."
    Else
        MsgBox Err.Number & ": " & Err.Description
    End If
    
    Resume Exit_Here
    
End Sub
 
Sean,

Thank you very much for your post, it was extremely helpful. However, the below code does not work for me and I cannot understand why:

Code:
Private Sub CmdViewHardcopy_Click()

On Error GoTo HandleError
 
    Dim strPath As String
    
    strPath = "J:\AssemblyIssues\Hardcopies" & Me!OrderNumber & ".pdf"
    
    Application.FollowHyperlink strPath
        
Exit_Here:

    Exit Sub
 
HandleError:

    If Err.Number = 490 Then 'No file was found
        MsgBox "No Hardcopy Found"
    Else
        MsgBox Err.Number & ": " & Err.Description
    End If
    
    Resume Exit_Here

End Sub

Access detects the correct OrderNumber, and the pdf file is named after the OrderNumber correctly. both are 14993236 but it can't seem to open up the pdf. Any ideas?

--Bill
 
Are you getting an error message? If so, what message?

If no error message, is anything happening?
 
I found the problem, I forgot a backslash! It should have been:

strPath = "J:\AssemblyIssues\Hardcopies\" & Me!OrderNumber & ".pdf"

Thank you very much!
 

Users who are viewing this thread

Back
Top Bottom