Edit Hyperlink settings

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a hyperlink field for Excel or Word documents. The user will be
opening the form to either view/print or to edit. I am wondering if there is
a way for me to control how the document is opened (read only/not) and still
use the hyperlink field.

THANKS!
 
I don't know that you can do this still using a hyperlink field, but how
about:

-using a plain textbox, IsHyperlink = False
-change the font to blue, underscore

-trap the Click event of the textbox.

*Air Code*
- assumes textbox is named txtDocument
- assumes read-only status is stored in bReadOnly (could be control on form,
etc.)
- uses References to Word and Excel
- could be done with late binding (Dim As Object,
CreateObject("Word.Application"))

Select Case Right(txtDocument, 4)
Case ".doc"
Set appWord = New Word.Application
appWord.Documents.Open txtDocument, , bReadOnly
Set appWord = Nothing
Case ".xls"
appExcel = New Excel.Application
appExcel.Workbooks.Open txtDocument, , bReadOnly 'third argument is
read-only state
Set appExcel = Nothing
Case Else
'for unspecified types, you can't force a read-only
'you can still use the Windows associated action with
FollowHyperlink
Application.FollowHyperlink txtDocument
End Select

-------------
Opening a file as read-only is dependent on application-specific
information. However, you probably will know ahead of time the important
types of documents to use and can spell out specific code. Use
Application.FollowHyperlink to revert to "old way"

HTH,

Kevin
 
Thank you for this code! It worked beautifully, only I put it on a label.
However, now I have another problem! I don't have any idea why/how - sorry,
learning here! I have a text box which is bound to the hyperlink field in my
table. According to the data entered by the user, I set the value of the
text box with the full path of this new doc. The textbox has the "Hyperlink"
property set to "yes" - however, it isn't working - any ideas??

THANKS!
 
Back
Top