Opening a PDF from a Command Button on a Form

David Ball

Registered User.
Local time
Today, 15:26
Joined
Aug 9, 2010
Messages
230
Hi,

I have a form with a Combo Box (Combo3) where I can select Part Numbers.
I have a Command Button (Command10) that I am trying to use to open a PDF drawing with a file name that matches the part number. (The PDF’s have file names the same as the Part Numbers).

The code I have been trying is:

Private Sub Command10_Click()
Application.FollowHyperlink ("C:\Drawings\ " & Me.[Combo3] & ".pdf")
End Sub

One possible problem is that the Part Numbers are of the format GFH-Q-1401-02 and when I tried entering a part number directly into my code to test that I noticed that Access changed it to GFH-Q1401-2, helpfully removing the zero. This will no longer match my drawing file name.
How can I modify my code to get this working?
Thanks very much
 
One possible problem is that the Part Numbers are of the format GFH-Q-1401-02 and when I tried entering a part number directly into my code to test that I noticed that Access changed it to GFH-Q1401-2, helpfully removing the zero. This will no longer match my drawing file name.

Did it also remove the hyphen after Q? Or was that a typo?

Try forcing a string value

Code:
Private Sub Command10_Click()

Dim strText As String
strText = CStr(Me.Combo3)

Application.FollowHyperlink ("C:\Drawings\" & strText & ".pdf")
End Sub

NOTE: I've removed the space you had at the end of "C:\Drawings"
 
It works, thanks very much
 
Is there a way to reference another field in the source query rather than the value of Combo3?
Combo3 is the Part Number. The problem I have is that there are many Parts shown on each drawing. In my table (and query) I have the drawing number for each part (Dwg_Num).
Can I select a Part Number in the Combo Box (Combo3) and have my code somehow pick up the associated Dwg_Num value from the source query (qryPartNums)?
Thanks very much
 
Colin,

For your suggestion, wouldn't it be better to create the entire path and place it in the string FIRST, then simply use the string?

Code:
Private Sub Command10_Click()
Dim strText As String
   strText = "C:\Drawings\" & CStr(Me.Combo3) & ".pdf"
   Application.FollowHyperlink ( strText )
End Sub

I've found having everything together so I can see exactly what I'm about to pass often is easier to correct than doing any of the concatenation within the command.
 

Users who are viewing this thread

Back
Top Bottom