Calling a function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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(??????)
 
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.
 
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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top