Repeated code

fat controller

Slightly round the bend..
Local time
Today, 00:18
Joined
Apr 14, 2011
Messages
758
If a portion of code is repeated over and over in different controls on a form, can the code be stored in a module and then called upon at the point it is needed in the control's individual code?
 
yes, but it can be in the same module as the form module if you are only talking about one form.

Code:
private sub doeseverything()

    do something here

end sub

private sub ctrl1_afterupdate()

    doeseverything

end sub

private sub ctrl2_afterupdate()

    doeseverything

end sub
 
You can also pass the Control to the function.

Code:
Private Sub whatever(ctrl As Access.Control)
 
    With ctrl
        dothestuff
    End With
 
End Sub

Then call it with

whatever Me.ActiveControl

Another way is to use a function. The function can be called directly in the Event.
 
Thank you both :) I have the same process (essentially just requery & update field values) that take place on a number of occasions on a form, so that will save my old fingers wearing out :D
 

Users who are viewing this thread

Back
Top Bottom