So I have a three forms with text boxes, and I'm saving them to db on the last one, one is pretty huge and iterative so I'd like to write a loop. But when I try to loop through them it doesn't seem to grab them from the other form, what am I doing wrong?
For i = 1 To 12
Dim txtbox_bem As TextBox = CType(frm_new_prot_2.Controls("frm_new_prot_2.txtbox_bem1_" & i), TextBox)
Dim txtbox_soll As TextBox = CType(frm_new_prot_2.Controls("txtbox_soll1_" & i), TextBox)
Dim txtbox_messw As TextBox = CType(frm_new_prot_2.Controls("txtbox_messw1_" & i), TextBox)
Dim txtbox_einheit As TextBox = CType(Controls("frm_new_prot_2.txtbox_einheit1_" & i), TextBox)
Dim txtbox_max As TextBox = CType(Controls("frm_new_prot_2.txtbox_max1_" & i), TextBox)
Dim txtbox_min As TextBox = CType(Controls("frm_new_prot_2.txtbox_min1_" & i), TextBox)
Dim txtbox_tol As TextBox = CType(Controls("frm_new_prot_2.txtbox_tol1_" & i), TextBox)
Dim ckbox_ok As CheckBox = CType(Controls("frm_new_prot_2.ckbox_ok1_" & i), CheckBox)
command.CommandText = "INSERT INTO tb_1_" & i & " (Auftraggeber, Protokollnr, 1_" & i & "bem, 1_" & i & "soll, 1_" & i & "messw, 1_" & i & "einheit, 1_" & i & "max, 1_" & i & "min, 1_" & i & "tol, 1_" & i & "ok) VALUES ('" & Auftraggeber & "'," & Protokollnr & ",'" & txtbox_bem.Text & "','" & txtbox_soll.Text & "','" & txtbox_messw.Text & "','" & txtbox_einheit.Text & "','" & txtbox_max.Text & "','" & txtbox_min.Text & "','" & txtbox_tol.Text & "','" & ckbox_ok.Text & "')"
command.CommandType = CommandType.Text
command.ExecuteNonQuery()
MsgBox("success row " & i)
Next
As you see I tried different combinations. The error I'm getting is:
"System.NullReferenceException: 'Object reference not set to an instance of an object.' txtbox_bem was Nothing."