First, you are CORRECT to change Private Sub to Public sub for the click event.
Then in code you can do say this:
dim strF as String
dim F as Form
strF = "frmScheduledTransactionsPaid"
DoCmd.OpenForm strF, acNormal, "", "", , acNormal
Set F = Forms(strF)
If (F!DueDate <= Date And F!AutoEntry = -1) Then
Call F.Command25_Click
End If
' even F.Command25_Click will also work (with OUT the word call in front)
'
' and if you want, full type out would be this
Call Forms("frmScheduledTransactionsPaid").Command25_Click
so say we have formA with this:
And we add a code event to the button (right click) choose this:
We choose code builder, and now we have this code stub:
Private Sub Command5_Click()
' code here to walk the dog
' code here to clean the house
MsgBox "The dog has been walked, and the house is clean"
End Sub
As noted, we don't have to write/type in the Sub/End sub part - that automatic done for you.
Now, the goal here is to call that click button code OUTSIDE of the form - from another form, or even from a standard plane jane code module. So, as noted (and you done this!!!), change the "private" to public. (it defaults to private, since mode code in a form is JUST FOR the one form.
So we now have this:
Public Sub Command5_Click()
' code here to walk the dog
' code here to clean the house
MsgBox "The dog has been walked, and the house is clean"
End Sub
Ok, so now from a code module, or even say formB, we want to call the above button click "code" stub.
so, AS LONG as formA is open, we can do this. If formA is closed, then we can NOT call the code stub.
So, now say we create formB, and have this button code:
Private Sub Command8_Click()
Call Forms("FormA").Command5_Click
End Sub
So, use the above syntax to call the click button code stub inside of that form.
Just remember, if you do plan or want to call that code inside of that formA in this example, FormA MUST be open for the call to work.
If formA is open then ANY other form, or ANY other code, in other forms, or even code in a standard code module is free to call that FormA routine (but FormA must be open).
Regards,
Albert D. Kallal (Access MVP 2003-2017)
Edmonton, Alberta Canada