Button to Add Hyperlink to Subform

Toluene

New member
Local time
Today, 00:16
Joined
Mar 28, 2016
Messages
4
Hello,

Been using this site for awhile now to learn best I can. However, I've run into an issue when trying to create a button to add a hyperlink to a subform.

I'd like the button to add a new record to the subform, open the Hyperlink Dialoge Box, and then tie that new record to the Master Form.

Whenever I run the below code, it will allow me to add a new Hyperlink, however it does not tie it to the Master form. The interesting thing, is if I end the code after the hyperlink dialogue box has launched and rerun the code, it will work properly (essentially starting from a "blank" record on the Master Form)

Code:
Me.[SubForm].SetFocus
Me.[SubForm]![HyperlinkObject].SetFocus
DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acNext
DoCmd.RunCommand acCmdInsertHyperlink
Any help would be greatly appreciated,

Thanks!
Toluene
 
how about going directly to new record:

Me.[SubForm].SetFocus
Me.[SubForm]![HyperlinkObject].SetFocus
DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdInsertHyperlink
 
Thanks for the quick reply.

Just loaded in the code and gave it a go.

Going directly to the new record successfully adds the hyperlink, however, it does not link it to the master. I use a table to store the hyperlinks (since I needed an infinite number of hyperlinks per record). It creates the hyperlink in the proper table, but does not have the linked field ([ID]) filled in.

I hope that makes sense.

Toluene
 
use before update event of your subform to insert the id:

private sub subform_beforeupdate(cancel as integer)
if trim(me.id & "") = "" then me.id = me.parent!id
end sub
 
Unfortunately that didn't work. I forgot to mention (and I have a feeling this is key), that when I open the form itself it works (correctly). However, I use another form for tab control. This is when I run into problems when running the code.
 
regardless of the tab where your main form is, you can get the id from it.
if it is also a subform:

private sub subform_beforeupdate(cancel as integer)
if trim(me.id & "") = "" then me.id = me.Parent!mainformname.form!id
end sub
 
Okay, I think I've mostly deciphered what you're getting at. However, looking at the code, after I click the button (which launches the hyperlink dialogue), and select a file, the form goes to a null value (Parent of the hyperlink subform) and places the hyperlink in this "null" record. Thus, when I put in your code, it's working correctly, but it is just transferring a null value to and from the respective IDs.
 

Users who are viewing this thread

Back
Top Bottom