PRIVATE vs. PUBLIC procedure

  • Thread starter Thread starter AFKAFB
  • Start date Start date
A

AFKAFB

I've about ten forms that used the same private sub form_current()
code. unfortunately the code appears on each of the form whereas i
would prefer to have the code once as public sub routine

how do i write this code

it will need to say if thr form name is say Form A, form B, form C etc
then run the public form_current() procedure.

not all forms in the database use this code.
 
if anything in the code refers to the current form, with the Me keyword,
then you need to use an argument in the public sub to hold the form
reference, as

Public Sub isFormCurrent(ByVal frm As Form)

and replace the Me. (or Me!) reference in the code with frm. (or frm!)

another way you might handle it is to use the CodeContextObject reference in
the public sub, as

With CodeContextObject
' code goes here
End With

or

With Screen.ActiveForm
' code goes here
End With

in each of the above options, you would remove the Me keyword from the code,
leaving the reference as
.SomeProperty
or
!SomeControl

in all cases, you would call the public sub from each form's current event,
as

Private Sub Form_Current()
isFormCurrent
End Sub

hth
 
Back
Top