I have an access 2007 form with 18 textbox controls in two columns. They are to add colors and color codes to a vendor table when entering a new style. Column one's controls are named Color1, Color2, etc, and column two's controls are named Code1, Code2, etc.
The code below goes through the textbox controls on the form and gets the control's name and value fine.
I do realize I'll need to put another if/then type statement to only perform the actions if the control selected by the case statement has a name beginning with "color". I'll add that later.
If you see the sql statement, I'm trying to insert a new color/code combination by calling up the control with the name beginning with "code" and ending with the number associated with the "color" textbox currently being evaluated in the case select.
TL;DR, when textbox "color1" is being evaluated, I want the value of what is in "code1" to be a part of the sql statement as well. The number at the end is the link between the two.
I'm sure I'm probably using an incorrect reference for ctrlcode or something like that, but if someone knows what I'm trying to do and could help me get this working, I'd appreciate it.
Dim sql As String, ctrlcode As Control 'Also tried as Object
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox 'Only searching textboxes
'Debug.Print ctl.Name, ctl.Value
If Not IsNull(ctl.Value) Then
Debug.Print ctl.Name, ctl.Value, Right(ctl.Name, 1)
**Next line fails Runtime error 424, object required**
Set ctrlcode = frm.Controls("code" & Right(ctl.Name, 1))
Debug.Print ctrlcode.Value, "ctrlcode value"
sql = "INSERT INTO tblVendorColors (Stylecode, color, colorcode, coloravail)" _
& " VALUES (Styletext, '" & ctl.Value & "', '" & ctrlcode.value & "', true)"
Debug.Print sql
End If
Case Else
' pass
End Select
Next