On my form, it has many optionbuttons and textboxs. The total fields of the table for this form is 61. I would like to make it easier to save every field.
Private Sub cmdSave_Click()
Dim aa As String
Dim ii As String
Dim i As Integer
Dim Result As String
Dim other As String
Dim speed As String
Dim model As String
Dim sn As String
Dim brand As String
Dim n1 As Integer
Dim aa1 As String
Dim n2 As Integer
Dim aa2 As String
Dim n3 As Integer
Dim aa3 As String
Dim n4 As Integer
Dim aa4 As String
Dim n5 As Integer
Dim aa5 As String
Dim n6 As Integer
Dim aa6 As String
Dim ctl As Control
Dim Str() As String
Dim n As Integer
Str = Split("CPU,Case,PCI,Sound,Hard,Memory,Modem,Mouse,Operating,SCSI,CD,Floppy,Monitor,Speakers,Netword,Motherboard", ","
Set rsHard = DataEnvironment1.rsHardware
If rsHard.State = adStateOpen Then rsHard.Close
DataEnvironment1.Hardware
rsHard.AddNew
For Each ctl In Controls
For i = LBound(Str) To UBound(Str)
Result = InStr(ctl.Name, Str(i))
If Result > 0 Then
Result = 0
If TypeOf ctl Is OptionButton Then
If ctl.Value = True Then
For n1 = 0 To rsHard.Fields.Count - 1
If (rsHard.Fields(n1).Name = Str(i)) Then
rsHard.Fields(n1).Value = ctl.Caption
Exit For
End If
Next n1
End If
End If
If TypeOf ctl Is TextBox Then
other = InStr(ctl.Name, "Other"
If (other > 0) Then
For n2 = 0 To rsHard.Fields.Count - 1
aa2 = InStr(rsHard.Fields(n2).Name, "Other" + Str(i))
If aa2 > 0 Then
rsHard.Fields(n2).Value = ctl.Text
End If
Next n2
End If
speed = InStr(ctl.Name, "Speed"
If (speed > 0) Then
For n3 = 0 To rsHard.Fields.Count - 1
aa3 = InStr(rsHard.Fields(n3).Name, "Speed" + Str(i))
If aa3 > 0 Then
rsHard.Fields(n3).Value = ctl.Text
End If
Next n3
End If
model = InStr(ctl.Name, "Model"
If (model > 0) Then
For n4 = 0 To rsHard.Fields.Count - 1
aa4 = InStr(rsHard.Fields(n4).Name, "Model" + Str(i))
If aa4 > 0 Then
rsHard.Fields(n4).Value = ctl.Text
End If
Next n4
End If
sn = InStr(ctl.Name, "SN"
If (sn > 0) Then
For n5 = 0 To rsHard.Fields.Count - 1
aa5 = InStr(rsHard.Fields(n5).Name, "Model" + Str(i))
If aa5 > 0 Then
rsHard.Fields(n5).Value = ctl.Text
End If
Next n5
End If
brand = InStr(ctl.Name, "Brand"
If (brand > 0) Then
For n6 = 0 To rsHard.Fields.Count - 1
aa6 = InStr(rsHard.Fields(n6).Name, "Model" + Str(i))
If aa6 > 0 Then
rsHard.Fields(n6).Value = ctl.Text
End If
Next n6
End If
End If
End If
Next i
Next ctl
rsHard.Update
If rsHard.State = adStateClosed Then rsHard.Open
End Sub
Private Sub cmdSave_Click()
Dim aa As String
Dim ii As String
Dim i As Integer
Dim Result As String
Dim other As String
Dim speed As String
Dim model As String
Dim sn As String
Dim brand As String
Dim n1 As Integer
Dim aa1 As String
Dim n2 As Integer
Dim aa2 As String
Dim n3 As Integer
Dim aa3 As String
Dim n4 As Integer
Dim aa4 As String
Dim n5 As Integer
Dim aa5 As String
Dim n6 As Integer
Dim aa6 As String
Dim ctl As Control
Dim Str() As String
Dim n As Integer
Str = Split("CPU,Case,PCI,Sound,Hard,Memory,Modem,Mouse,Operating,SCSI,CD,Floppy,Monitor,Speakers,Netword,Motherboard", ","
Set rsHard = DataEnvironment1.rsHardware
If rsHard.State = adStateOpen Then rsHard.Close
DataEnvironment1.Hardware
rsHard.AddNew
For Each ctl In Controls
For i = LBound(Str) To UBound(Str)
Result = InStr(ctl.Name, Str(i))
If Result > 0 Then
Result = 0
If TypeOf ctl Is OptionButton Then
If ctl.Value = True Then
For n1 = 0 To rsHard.Fields.Count - 1
If (rsHard.Fields(n1).Name = Str(i)) Then
rsHard.Fields(n1).Value = ctl.Caption
Exit For
End If
Next n1
End If
End If
If TypeOf ctl Is TextBox Then
other = InStr(ctl.Name, "Other"
If (other > 0) Then
For n2 = 0 To rsHard.Fields.Count - 1
aa2 = InStr(rsHard.Fields(n2).Name, "Other" + Str(i))
If aa2 > 0 Then
rsHard.Fields(n2).Value = ctl.Text
End If
Next n2
End If
speed = InStr(ctl.Name, "Speed"
If (speed > 0) Then
For n3 = 0 To rsHard.Fields.Count - 1
aa3 = InStr(rsHard.Fields(n3).Name, "Speed" + Str(i))
If aa3 > 0 Then
rsHard.Fields(n3).Value = ctl.Text
End If
Next n3
End If
model = InStr(ctl.Name, "Model"
If (model > 0) Then
For n4 = 0 To rsHard.Fields.Count - 1
aa4 = InStr(rsHard.Fields(n4).Name, "Model" + Str(i))
If aa4 > 0 Then
rsHard.Fields(n4).Value = ctl.Text
End If
Next n4
End If
sn = InStr(ctl.Name, "SN"
If (sn > 0) Then
For n5 = 0 To rsHard.Fields.Count - 1
aa5 = InStr(rsHard.Fields(n5).Name, "Model" + Str(i))
If aa5 > 0 Then
rsHard.Fields(n5).Value = ctl.Text
End If
Next n5
End If
brand = InStr(ctl.Name, "Brand"
If (brand > 0) Then
For n6 = 0 To rsHard.Fields.Count - 1
aa6 = InStr(rsHard.Fields(n6).Name, "Model" + Str(i))
If aa6 > 0 Then
rsHard.Fields(n6).Value = ctl.Text
End If
Next n6
End If
End If
End If
Next i
Next ctl
rsHard.Update
If rsHard.State = adStateClosed Then rsHard.Open
End Sub