austin350s10
Active Member
- Joined
- Jul 30, 2010
- Messages
- 321
So I am working on a userform that populates all of its fields from a database (works flawlessly). The problem comes in when I attempt to UPDATE the database with any changes to the userform fields. To make matching easy, each userform field name is also a column name in the database. So i figured i could just run through each control on the userform and assign its value to the database when updating. My idea works but, it takes forever as there are over 300 controls on my userform. Does anyone know of a more efficient way to do this?
I already tried grouping multiple SQL strings together and running one execute command but, being that there are some extra controls on my userform that are not in my database, I keep getting errors.
My slow but working attempt:
I already tried grouping multiple SQL strings together and running one execute command but, being that there are some extra controls on my userform that are not in my database, I keep getting errors.
My slow but working attempt:
Code:
Private Sub btnSaveChanges_Click()
Dim ctl As MSForms.Control
Set Sql = SQLconnect("myserver login")
For Each ctl In Me.Controls
On Error Resume Next
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "CheckBox" Or TypeName(ctl) = "ComboBox" Then
sqlstr = "UPDATE Clients SET " & ctl.Name & " = '" & ctl.Value & "' WHERE idClients = '1';"
Sql.Execute sqlstr
End If
Next ctl
End Sub