I wanted to open the form "frmContacts" from three different places: the form double click and the firstname and lastname controls double click events. Rather that write the same code three times (a valid option), I wrote a UDF (user defined function) and called it three times.
Now if I want to modify the code by opening a different form, I only have to change the code in one place, instead of three places.
I need to open the form "frmContacts" to a specific record, which is the PK field.
In the sub "OpenContacts", I could have used almost any word (but not reserved words) for the parameter. In my naming convention, I use the prefix "p" to denote a parameter variable. Easier for me to see where values come from...
For instance, I could have used "banana" and the code would have looked like
Code:
Sub OpenContacts(banana As Long)
DoCmd.OpenForm "frmContacts", , , "ContactID_PK = " & banana
End Sub
whenever OpenContacts is run (as on a double click)
Not so much "where it is run" as "where the UDF "OpenContacts" is called from". But you are on the right track.
Look up the "Call" keyword.