Use field name as a parameter in a subroutine or function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bassi.carlo@gmail.com

    #1

    Use field name as a parameter in a subroutine or function

    I have an application with many combobox in different forms used for
    choose a particular length (for example items are "ft" - feet, "in" -
    inch, "m" - meters, and so on).
    I don't want to put in every form (class), in load event, the code
    needed to load items from a Db table using items.add.
    I want to create a public subroutine (or function), when i call it I
    pass, as a parameters, the form and field name, then the subroutine
    read from the table and add items in the form/field I have passed as
    parameters.
    I don't know if I can do that and how.
    Any suggestion?

  • Phillip Taylor

    #2
    Re: Use field name as a parameter in a subroutine or function

    On Nov 9, 9:51 am, bassi.ca...@gma il.com wrote:
    I have an application with many combobox in different forms used for
    choose a particular length (for example items are "ft" - feet, "in" -
    inch, "m" - meters, and so on).
    I don't want to put in every form (class), in load event, the code
    needed to load items from a Db table using items.add.
    I want to create a public subroutine (or function), when i call it I
    pass, as a parameters, the form and field name, then the subroutine
    read from the table and add items in the form/field I have passed as
    parameters.
    I don't know if I can do that and how.
    Any suggestion?
    Your function should be in a module and probably look like this:

    Public Sub AddItemsToCombo Box(byref combo as ComboBox,byval field as
    String,byval table as String)
    combo.items.cle ar()

    'get the records from the database
    combo.items.add (field & " from function")
    combo.items.add ("another record")

    end sub

    and then you can call it like this:

    public sub form_load(...)

    AddItemsToCombo Box(ComboBox1," fieldname","tab lename")

    end sub

    That's all you should need to do. Adapt this as you need it :-)

    Phill

    Comment

    Working...