Calling a function

G

Greg

Hi, I currently have a Sub procedure which has the following line of code in
it:
txt_FromCode = [cbo_FromTown].Column(5)
Similar procedures exist, with only a change in combo box name. I plan to
change this Sub into a Function and then call the function from each combo
box event. How do I refer to the combo box name in the function?:
txt_FromCode = ????.Column(5)
What should I dim ComboName as?:
Function CBF_UpdateFields (ComboName as ????)
What would the Call statement look like:
Call CBF_UpdateFields(??????)
 
D

Douglas J. Steele

Declare the function as:

Function CBF_UpdateFields (ComboName as ComboBox)

or

Function CBF_UpdateFields (ComboName as Control)

Refer to the combo box as:

txt_FromCode = ComboName.Column(5)

Invoke the function as:

Call CBF_UpdateFields(Me.MyComboBox)

(replace MyComboBox with the name of the actual combo box)

Of course, if you're only going to use the Call statement, you may as well
declare CBF_UpdateFields as a Sub, not a Function.
 
G

Graham Mandeno

Hi Greg

If the combo box you want to refer to is the control that currently has the
focus, then use Me.ActiveControl:

Private Function SetFromCode()
txt_FromCode = Me.ActiveControl.Column(5)
End Function

Then set the AfterUpdate property for each of the combos to:
=SetFromCode()
 
Top