Disabling certain hyperlinks in a subform

  • Thread starter Thread starter Bill Murphy
  • Start date Start date
B

Bill Murphy

I have a subform where one column named FileName is formatted as a
hyperlink, and contains the full path and names of files located on the
user's local drive or network drive. I would like the user to be able to
preview Word, Excel and PDF documents, but prevent certain file types from
opening, such as zip files. Here's some sample code that I tried in order
to prevent a zip file from being opened when the user clicks on the
hyperlink:

If Right(FileName, 4) = "zip#" Then
MsgBox "Zip files cannot be previewed"
Exit Sub
End If

The # is needed since this is stored in the hyperlink by Access. This code
runs, but as soon as the sub is exited Access tries to open the zip file. I
tried conditional formatting for this column, but the IsHyperlink format
can't be removed at run time.

Is there a way to prevent certain file types such as zip files from being
executed in the click event?

Bill
 
Hi Bill,

A small test suggests that the MouseDown event provides a solution to your
problem.
The (obvious) Click event seems to fire too late or not at all on a
(populated) Hyperlink.

Try something like:

Private Sub Path_and_Filename_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
'Debug.Print Me.Path_and_Filename
If Right(Me.Path_and_Filename, 5) = ".zip#" Then DoCmd.CancelEvent
End Sub

Works fine on xxxx.txt - click opens up Notepad
Does nothing on yyy.zip

Good luck
CD
 
Back
Top