You can also take the approach of passing the control name
Public Sub DoControlChange(C As Control) if C.Value ="foo" then 'stuff end if End Sub
"John Nurick" <j.mapSoN.nurick[ at ]dial.pipex.com> wrote in message news:sdub02tfsclqk97gffe1jvoa63c8nbua1a[ at ]4ax.com...
[Quoted Text] > Basically, if you've got code in a form's module along these lines: > > Private Sub XXX_AfterUpdate() > Me.This > Me.That > Me.TheOther > End Sub > > you can move the bulk of it into a procedure in a standard module: > > Public Sub CommonAfterUpdate(F As Form) > F.This > F.That > F.TheOther > End Sub > > which you can call from the individual AfterUpdate events like so: > > CommonAfterUpdate Me > > Note, however, that if there's only one form involved, you could put the > common procedure in the form's own module. In that case, the Me keyword > would still refer to the form, and about the only change you'd have to > make would be to use > Me.ActiveControl > instead of > Me.ListboxName > to refer to the listbox from whose AfterUpdate event the procedure had > been called. > > > On Wed, 1 Mar 2006 09:47:27 -0800, "cbjames" > <cbjames[ at ]discussions.microsoft.com> wrote: > >>I am new to writing Modules. >>I have a Form containing a Chart. There are a series of listboxes on the >>form that changes values and such on the chart as different selections are >>made. I have the same 20+ lines of VBA code attached to the AfterUpdate() >>event of the listboxes. I want to move this code to a Module so when I >>make >>changes or add listboxes I do not have to change ever incident of the 20+ >>lines. >> >>The problem is the code "copied" into the module does not run. It does not >>seem to like referencing "Me.[fieldname]". I get an "error 424". Here is >>one >>simple line of code that sets the value of the chart title. If I can get >>the >>syntax right on this in a Module I think I can write the rest. >> >>"Me.chartTitle = "Chart: " & [selectChart] & " . Unit: " & [selectUnit] & >>" >>. Employee: " & [selectEmployee]" >> >>The fields; [selectChart], [selectUnit], [selectEmployee] are values >>selected in the listboxes. I did DIM them as Strings. >> >>Any thoughts? > > -- > John Nurick [Microsoft Access MVP] > > Please respond in the newgroup and not by email. >
|