So I’ve got this code to loop through each controls in a form and create and update sql based on their names and values, text or caption.
Dim sql as String
Dim ctr as Control
sql = "update table set "
For Each ctr In Me.Controls
If TypeOf ctr Is TextBox Then
If ctr.Container = "Carton Config data input" Then
sql = sql & ctr.name & " = " & "'" & ctr.Text & "',"
End If
ElseIf TypeOf ctr Is OptionButton Then
If ctr.Value = True Then
sql = sql & " status = '" & ctr.Caption & "',"
End If
ElseIf TypeOf ctr Is CheckBox Then
If ctr.Value = 1 Then
sql = sql & ctr.name = "'OK',"
ElseIf ctr.Value = 0 Then
sql = sql & ctr.name = "'',"
End If
End If
Next
After that I add the where conditions of course but it doesn’t matter now.
The problem is when it gets to a checkbox, the sql’s value will be “False” and I have no idea why.
The length of the string shouldn’t be a problem, the first checkbox that makes this is the 4th object, so the string is not too long. Besides, without the checkbox part, it works like a charm.
So could someone help me?
Thanks in advance.
I found the problem so I will just answer it for those who might need it.
It was a simple syntax error:
Just replaced:
With: