Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Location
    Pascagoula, MS
    Posts
    6

    Unanswered: Control Arrays in Access?

    I am new to working with Access, and we currently use 97. I am farily knowledgeable in VB and I know that I can use an array of text boxes to input information. However, I have realized that I make a control array in Access like I can in VB.

    So my question:

    Rather than use a Subform, I have have 9 rows of 3 text boxes (this is an input form only. For modify/delete, it will use a subform). First Col. is QTY, second is PC, and thid is DESC and all are used to input part information used to mount equip to a foundation onboard navy ships.

    When a user saves the main form, I would like a loop to read each txt box value, and then store that in the hardware_list table. I can save to the h_table with no problem, the problem is actually reading the values from each text box on each row. I either get a NULL as a value, or I get the name of the variable used. For instance, here is what I was trying to use:

    DIM i as integer
    Dim txtBoxInfo as String
    for i = 0 to 3
    txtBoxInfo = "MyField" & Format$(i)
    me(TextControl) = TextControl
    next i

    where, in this case, an series of text boxes named MyField have been created.

    Can anyone help me with this and offer some suggestions? And are there any plans to implement control arrays in future version of Access? I have not used 2000 above so maybe it already has.

    Thanks very much in advance.

    R/

    Chris

  2. #2
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: Control Arrays in Access?

    Originally posted by cyauch
    I am new to working with Access, and we currently use 97. I am farily knowledgeable in VB and I know that I can use an array of text boxes to input information. However, I have realized that I make a control array in Access like I can in VB.

    So my question:

    Rather than use a Subform, I have have 9 rows of 3 text boxes (this is an input form only. For modify/delete, it will use a subform). First Col. is QTY, second is PC, and thid is DESC and all are used to input part information used to mount equip to a foundation onboard navy ships.

    When a user saves the main form, I would like a loop to read each txt box value, and then store that in the hardware_list table. I can save to the h_table with no problem, the problem is actually reading the values from each text box on each row. I either get a NULL as a value, or I get the name of the variable used. For instance, here is what I was trying to use:

    DIM i as integer
    Dim txtBoxInfo as String
    for i = 0 to 3
    txtBoxInfo = "MyField" & Format$(i)
    me(TextControl) = TextControl
    next i

    where, in this case, an series of text boxes named MyField have been created.

    Can anyone help me with this and offer some suggestions? And are there any plans to implement control arrays in future version of Access? I have not used 2000 above so maybe it already has.

    Thanks very much in advance.

    R/

    Chris
    Would this be anything like what you are looking for?

    Dim ctl as control, ctls as controls

    Set ctls = Me.Controls
    For each ctl in ctls

    If ctl.ControlType = acTextBox Then
    process textbox
    Else
    whatever you want to do.
    End If

    Next

    Gregg

  3. #3
    Join Date
    Oct 2003
    Location
    Pascagoula, MS
    Posts
    6
    Please excuse me if I am way off here, but wouldn't this check every text box control on the forum? Or, could I check the actual name of the check box control? Or, could I restrict the search to a specific set of text boxes (and how)? Using your code, could I place that in a loop, or use a counter, to find the box that I am looking for? Somehow I would need to find a text box txtQty(x) The next para. explains exactly how I have that set up on the form.

    For instance, in column one, I have text boxes named txtQty1 thru txtQty9. Same thing for Column 2 and 3, but using the name txtPc and txtDesc repsectively.

    I wish that MS would have thought to include this in Access since VB is used. I have never had to code arrays like this, and with VB it was automatic so I am getting confused and lost trying to find aswers on the net. Your post has been helpful and has opened a door to a new directioin that I haven't seen before.

    Thanks for the quick response.

  4. #4
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile

    Originally posted by cyauch
    Please excuse me if I am way off here, but wouldn't this check every text box control on the forum? Or, could I check the actual name of the check box control? Or, could I restrict the search to a specific set of text boxes (and how)? Using your code, could I place that in a loop, or use a counter, to find the box that I am looking for? Somehow I would need to find a text box txtQty(x) The next para. explains exactly how I have that set up on the form.

    For instance, in column one, I have text boxes named txtQty1 thru txtQty9. Same thing for Column 2 and 3, but using the name txtPc and txtDesc repsectively.

    I wish that MS would have thought to include this in Access since VB is used. I have never had to code arrays like this, and with VB it was automatic so I am getting confused and lost trying to find aswers on the net. Your post has been helpful and has opened a door to a new directioin that I haven't seen before.

    Thanks for the quick response.
    Within the loop you can check for the control name and process it accordingly.

    Using my previous code, use ctl.Name to refer to each textbox on the form.

    Gregg

  5. #5
    Join Date
    Oct 2003
    Location
    Pascagoula, MS
    Posts
    6
    again, thanks for the response. Here is where I am at right now:

    Set ctls = Me.Controls
    Dim temp1 As String
    For i = 1 To 9
    temp1 = "txtQty" + Format$(i)

    For Each ctl In ctls
    If ctl.ControlType = acTextBox Then
    if ctl.Name = temp1 Then
    rsMyRS.AddNew
    rsMyRS("fld_qty") = ctl.Name
    rsMyRS.Update
    End If
    End If
    Next

    Next i

    I understand how to get the Name, and its now taking the name of each text box and putting that in the table, but I want the value. Ideas? What am I mssing? I don't that much expreience using objects/classes in access.

  6. #6
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    Just use ctl to get the value you need. E.g. - strMyValue = ctl

Posting Permissions

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