Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011

    Unanswered: Include a variable in a text box name

    I'm trying to include a variable in a text box name in my SQL... For example, I have a recordset that I'm looping through and posting values to text boxes tahat are read in my SQL. The name is in the form of '" & Me.txt_TextBoxName_quarter1.value & "'. I would like to include a variable in place of the 1 so that on the first iteration it's = 1, 2nd iteration = 2 etc., etc. I've tried '" & IterationNumber & "' and a few other combinations of ' or " but can't get my SQL to compile.
    Thanks for any help.
    Jack Kent
    Lavallette, NJ

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 14
    Not sure to understand precisely what you're looking to achieve. If you want to dynamically address several controls of the form (i.e. "txt_TextBoxName_quarter1", then "txt_TextBoxName_quarter2", etc.), you can compose the name of the control and address it through the Controls collection of the form:
    Dim i as Long
    Dim strCtlName as String
    dim varSomeVariable as Variant
    For i = 1 to 4
        strCtlName = "txt_TextBoxName_quarter" & i
        varSomeVariable = Me.Controls(strCtlName).Value
    Next i
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts