Link to home
Create AccountLog in
Avatar of gettechnical
gettechnical

asked on

VB Code for Command Button to click on Hyperlink in Table

Hello Experts!
I am reconfiguring an Access 2007 database to remove macro commands and use Visual Basic code.  I've been able to do so with all other controls in my Form save one (with the help of your site).  My abilities in Visual Basic are very rudimentary so I need your expertise.  I'm hoping I can explain this in a manner that it makes sense.

I would like to write VB code for a command button in a Form so that when the user clicks on the button, it opens an external PDF unique to each record.  My thoughts were that I should create a hyperlink field in the Table to link to the PDFs folder for each record.  Then to create VB code in the command button's OnClick Event Procedure in the Form that jumps to the Table's hyperlink field of that same record to open each unique PDF.

Here are the variables:
Form Name = F_AR_Entry
Form's Command Button Name: View_Doc1
Table Name = T_DocList
Table's Field Name where Hyperlink to PDF is Stored = View_Doc
Record ID# Used in Attachments: E003
Name of Folder Where PDFs are Stored: 03.12.09 MBJR TEST
PDF File Name: E003.pdf

I'm a beginner - so I don't have any code to add since I don't know where to start w/ this.  I've attached snapshot screens that will hopefully illustrate what I'm trying to do.

I appreciate your help!
Slide1.JPG
Slide2.JPG
Slide3.JPG
ASKER CERTIFIED SOLUTION
Avatar of ioane
ioane
Flag of New Zealand image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of rockiroads
Here is a question for you. Does the data held hold the relative path i.e.

03.12.09 MBJR TEST\E003.pdf

or fullpath eg

C:\03.12.09 MBJR TEST\E003.pdf

Reason why I ask is that followhyperlink (or any call for that matter) will not find it if its a relative path and you are not in the parent directory.

If its relative path, you may need to either specify the full path or change directory to parent directory i.e. chdir ("C:\")  
if your app depends on running in a certain location you would need to change directory back to where you originally was
Avatar of gettechnical
gettechnical

ASKER

Thank you Tramtrak!  (I thought it would be more involved than that.) It worked.  
Rockiroads - I have the database and files stored on the Desktop as:
[Folder] GP_Database
     [Application] GP_DB
     [Folder] 03.12.09 MBJR TEST (contains PDFs)
It was able to locate the scans w/ Tramtrak's code.  This setup will be moved to another computer (but still on the Desktop with the same setup).  Will I need to make any adjustments?
ALSO, can we add a MsgBox line in the code above that will pop-up if there is nothing in the hyperlink field that says "Scanned version of this document is not available at this time."
Thanks again!  I need to learn VB code.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Rockiroads.  Good point on the common directory.  Your code for the message box does exactly what I want.  Thank you.
The reason is that I have attorneys using this database, and I'm not sure if I'll have hard copy scans to hyperlink to each record yet.  If I don't and they click on the button and it appears nothing occurs, they won't be a happy bunch.
I'll distribute points to you both.
Excellent work.  This site is a great resource.
ok m8, good luck with the rest of your work then :)