Hyperlink to open Word doc

J

JIM

Hi all, I have a command button on a subform. Which clicked I want to print
out a word document whose path and name is in textbox. So far I'm just
opening form in code but I can't get it to work. Here's code so far:

Private Sub Option60_Click()
Dim str As String
str = [Me!txtRoofPlanLoc] 'this is name of control that contains
path
Application.FollowHyperlink str
On Error GoTo ErrOption60

MsgBox "You are trying to open " & vbCrLf & str
Exit_Option60_Click:
Exit Sub

ErrOption60:
MsgBox Err.Description
Resume Exit_Option60_Click
End Sub

I even added message box to see what it's trying to open but message box
doesn't appear. So for some reason I'm not even getting to message. I
checked - the event coding is on the on click event. What am I missing?
Thanks, JIM
 
D

Daniel Pineault

Try

Private Sub Option60_Click()
Dim str As String
str = Me.txtRoofPlanLoc 'this is name of control that contains
path
Application.FollowHyperlink str
On Error GoTo ErrOption60

MsgBox "You are trying to open " & vbCrLf & str
Exit_Option60_Click:
Exit Sub

ErrOption60:
MsgBox Err.Description
Resume Exit_Option60_Click
End Sub

this will open the doc not print it. and the control must have the fullpath
and filename.

To print it out I would suggest you look at

http://www.pacificdb.com.au/MVP/Code/ExeFile.htm

place it in a module and then mod your code to something like

Private Sub Option60_Click()
Dim str As String
str = Me.txtRoofPlanLoc 'this is name of control that contains
path
ExecuteFile(str,"Print)

On Error GoTo ErrOption60

MsgBox "You are trying to open " & vbCrLf & str
Exit_Option60_Click:
Exit Sub

ErrOption60:
MsgBox Err.Description
Resume Exit_Option60_Click
End Sub
--
Hope this helps,

Daniel Pineault
For Access Tips and Examples: http://www.cardaconsultants.com/en/msaccess.php
If this post was helpful, please rate it by using the vote buttons.
 
J

JIM

Thanks, Daniel that helps a lot. I will definately use the print function
later. What was happening with my code is I limit input on the subform with
a subroutine:

Private Sub Form_Load()

If CurrentProject.AllForms("frmClientBuildings").IsLoaded Or Parent.Name
= "frmWorkOrders" Then
Me.AllowEdits = False 'do not allow
edits if a subform or subform of frmWorkOrders
Me.AllowAdditions = False
Else
If Parent.Name = "frmCustomer" Then 'allow edits if a
subform of frmCustomers
Me.AllowEdits = True
Me.AllowAdditions = True
End If
End If
End Sub

So when I clicked on command button event was not fired. Silly if me to
forget that. Is there a way to activate only the command button?
Thanks, JIM

Daniel Pineault said:
Try

Private Sub Option60_Click()
Dim str As String
str = Me.txtRoofPlanLoc 'this is name of control that contains
path
Application.FollowHyperlink str
On Error GoTo ErrOption60

MsgBox "You are trying to open " & vbCrLf & str
Exit_Option60_Click:
Exit Sub

ErrOption60:
MsgBox Err.Description
Resume Exit_Option60_Click
End Sub

this will open the doc not print it. and the control must have the fullpath
and filename.

To print it out I would suggest you look at

http://www.pacificdb.com.au/MVP/Code/ExeFile.htm

place it in a module and then mod your code to something like

Private Sub Option60_Click()
Dim str As String
str = Me.txtRoofPlanLoc 'this is name of control that contains
path
ExecuteFile(str,"Print)

On Error GoTo ErrOption60

MsgBox "You are trying to open " & vbCrLf & str
Exit_Option60_Click:
Exit Sub

ErrOption60:
MsgBox Err.Description
Resume Exit_Option60_Click
End Sub
--
Hope this helps,

Daniel Pineault
For Access Tips and Examples: http://www.cardaconsultants.com/en/msaccess.php
If this post was helpful, please rate it by using the vote buttons.



JIM said:
Hi all, I have a command button on a subform. Which clicked I want to print
out a word document whose path and name is in textbox. So far I'm just
opening form in code but I can't get it to work. Here's code so far:

Private Sub Option60_Click()
Dim str As String
str = [Me!txtRoofPlanLoc] 'this is name of control that contains
path
Application.FollowHyperlink str
On Error GoTo ErrOption60

MsgBox "You are trying to open " & vbCrLf & str
Exit_Option60_Click:
Exit Sub

ErrOption60:
MsgBox Err.Description
Resume Exit_Option60_Click
End Sub

I even added message box to see what it's trying to open but message box
doesn't appear. So for some reason I'm not even getting to message. I
checked - the event coding is on the on click event. What am I missing?
Thanks, JIM
 

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