CrazyAccessProgrammer said:
Is it possilbel to VBA Code event that you always want to occur based on a
form event?
Say I always want certain code to run on a form's OnCurrent event. Is
there
a way to invoke this code without having to place a call to the procedure
in
every single form in my database?
well, you can put the name of the function in the forms property setting.
Thus, in theory, you don't actually have to place code in the forms
on-current event.....
This also means it quite easy to write code that would update all forms to
have this setting.
This "trick" also works if you select 10 controls on a form, and then type
in the name of a function for some event/property for those controls. You
only have to type in the function name once, and "all" controls you selected
will now run that code for the given event.
The limitation in the above is that you can't use this trick for events that
have parameters (such as the before update event).
The format for the property setting is:
=NameOfFunction()
that function can be global function in a standard code module...
In the "general" code module, you can't use "me" anymore, but the code can
be written as:
Public Function AskInvoicePrint()
Dim tblgroupid As Long
Dim frmActive As Form
Set frmActive = Screen.ActiveForm
tblgroupid = frmActive.frmMainClientB.Form!ID
If frmActive.InvoiceNumber = 0 Then
frmActive.InvoiceNumber = nextinvoice
frmActive.Refresh
End If
The above is the same approach I use for menu bars (and now ribbon) code
that gets run when you click on the menu/ribbon. Note how the code picks up
the active form, and thus I use "rmActive" in place me.