Hyperlink on Subform not working

dark11984

Registered User.
Local time
Today, 18:52
Joined
Mar 3, 2008
Messages
129
Hi,
I am having trouble with getting an on click command button to work on my subform. When clicked it is supposed to run the hyperlink command. I've got the same code on my main form and works fine but on my subform you click the button and nothing happens. Can someone tell me where i'm going wrong? cheers.

Code:
Private Sub Cmdhyperlink_Click()
On Error GoTo err_Cmdhyperlink_Click
    Me.[TxtHyperlink].SetFocus
    DoCmd.RunCommand acCmdInsertHyperlink
 
exit_Cmdhyperlink_Click:
    Exit Sub
 
err_Cmdhyperlink_Click:
    MsgBox "Hyperlink cancelled."
    Resume exit_Cmdhyperlink_Click
 
End Sub
 
Your SetFocus line is incorrect. Your setfocus of Me.txthyperlink assume that the field is on the parent form, which it is not.

So the correct syntax to refer to a control(textbox or what ever) on a subform is:

Me!NameOfSubformConteiner.Form!NameOfControl.SetFocus
(Replace the names in red with your names of these controls)

However SetFocus property isen't availeble directly from the parentform, so the trick is to setfocus to the subformConteiner first and then to another SetFocus to point to the control.

Code:
Private Sub Cmdhyperlink_Click()
On Error GoTo err_Cmdhyperlink_Click
    [COLOR=red]Me!NameOfSubformContainer.SetFocus[/COLOR]
[COLOR=red]    Me!NameOfSubformContainer.Form!txtHyperlink.[/COLOR][COLOR=red]SetFocus[/COLOR]
    DoCmd.RunCommand acCmdInsertHyperlink
 
exit_Cmdhyperlink_Click:
    Exit Sub
 
err_Cmdhyperlink_Click:
    MsgBox "Hyperlink cancelled."
    Resume exit_Cmdhyperlink_Click
 
End Sub

Hope this helps.

JR
 

Users who are viewing this thread

Back
Top Bottom