Scenario: I need to be able to copy the access functionality where "Right Click, then go to hyperlink, then edit hyperlink, find the photo and click ok to add the link to the image ". Our users now only have access to the runtime and can no longer accomplish this.
Problem: I have searched on the internet and it tells me to use Application.Dialogs to open the dialog. Only problem is that I don't have that option. Would anyone be able to tell me which reference I need to add开发者_运维知识库 to accomplish this? Or is there another way to open that dialog?
DoCmd.RunCommand acCmdEditHyperlink
will open the Hyperlink insert / edit dialog.
"Cleaner" solution (if you can make the corresponding changes): store the path as text in your DB and open it via Application.FollowHyperlink
on whatever event you prefer.
I read this whole page and found a wonderful and fast solution! All I did was apply the advice to set the focus to my textbox.
Here is the subroutine that I constructed based on the above:
Private Sub cmdHyperlink_Click()
Me.txtPDFLink.SetFocus
DoCmd.RunCommand acCmdEditHyperlink
End Sub
It works perfectly and is actually much easier and faster than the right-click, which I disabled to prevent users from closing the form or placing it in design mode, which they should not be doing.
For future users trying to accomplish this I ended up having to send the key press to open the dialog box. You need to remember to set the focus back onto your textbox before sending the key or else it won't work.
Private Sub Command24_Click()
Text35.SetFocus
SendKeys ("^k")
End Sub
Another possible solution using DoCmd.RunCommand acCmdEditHyperlink
is to do so from a double click within the hyperlinked field.
Private Sub txtInvoiceOrReceiptLink_DblClick(Cancel As Integer)
On Error GoTo HandleErr
DoCmd.RunCommand acCmdEditHyperlink
ExitHere:
Exit Sub
HandleErr:
Select Case Err.Number
Case 2501 ' The RunCommand was canceled
Resume Next
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "br.Form_sfrmCashInflow.txtInvoiceOrReceiptLink_Enter"
End Select
Resume ExitHere
End Sub
By using a double click for the edit dialog box you can still single click merely to follow the hyperlink. The error handling code supresses the default message when the user cancels the edit dialogue box.
This solution works well in datasheets or continuous forms (in addition to forms in standard view), given that it doesn't require nominating the relevant record and field from outside that field (as you'll need to do if you are trying to bring up the edit diolog box from a commmand button).
The one drawback is that for fields with an existing hyperlink, double click will also fire the hyperlink (to bring up whatever file/resource the hyperlink points to). That is, in addition to firing up the edit dialog box.
精彩评论