none
Control naming problem RRS feed

  • Question

  • I have 24 textbox name from txtBT01 to txtBT24

    I try to create function like below

    Function Time(num As String)
        ["txtBT"& num].Enabled = True
        ...
    End Function

    Compiler give an error "External Name not defined"


    It there any other way to declare the control name?

    Thursday, November 24, 2016 7:17 AM

Answers

  • Try this:

    Function EnableControl(frm As Form,num As String)

        frm.Controls("txtBT" & num).Enabled = True

    End Function

    In the form's module you'd then call it like this:

        EnableControl Me,"01"

    From outside the form's module you'd call it like this:

        EnableControl Forms("YourFormNameGoesHere"),"01"

    Notice that I've changed the name of the function.  Time is the name of a built in function in Access, so should not be used as the name of another function.

    Ken Sheridan, Stafford, England


     
    Thursday, November 24, 2016 1:38 PM

All replies

  • Function Time(num As String)
        ["txtBT"& num].Enabled = True
        ...

    Hi David,

    You could try:    Me("txtBT" & num).Enabled = True,

    assumed that Time is defined within the form's module.

    By the way, I would not use Time as a function name, since it is a reserved word within Access. Just name it differently.

    Imb.

    Thursday, November 24, 2016 7:25 AM
  • Thank for the advise.

    it give an error,

    "Invalid use of Me Keyword"

    btw, I change the function name already.

    thank you

    Thursday, November 24, 2016 7:47 AM
  • "Invalid use of Me Keyword"

    Hi David,

    Did you declare your time-function in a standard (general) module? Then you should also pass a reference to the form on which the control is.

    If the time-function is declared in the module of the form on which the control is, then it should work with the keyword Me.

    Imb.

    Thursday, November 24, 2016 8:16 AM
  • Hello Imb,

    Yes, I declare the function in standard module.

    Then I try your suggestion in from module, it is working.

    what did I missing when pass reference ?

    Thank you.

    Thursday, November 24, 2016 8:56 AM
  • Then I try your suggestion in from module, it is working.

    what did I missing when pass reference ?

    Hi David,

    The most simple is to place the function in the form's module, then it works, as you have experienced.

    Let me know how to work when you want to place the function in a standard module. But it is a little more complicated.

    Imb.

    Thursday, November 24, 2016 11:20 AM
  • Try this:

    Function EnableControl(frm As Form,num As String)

        frm.Controls("txtBT" & num).Enabled = True

    End Function

    In the form's module you'd then call it like this:

        EnableControl Me,"01"

    From outside the form's module you'd call it like this:

        EnableControl Forms("YourFormNameGoesHere"),"01"

    Notice that I've changed the name of the function.  Time is the name of a built in function in Access, so should not be used as the name of another function.

    Ken Sheridan, Stafford, England


     
    Thursday, November 24, 2016 1:38 PM