I want to do a 'for loop' in an access database so that it loops through a number of text boxes and combo boxes (for different records for the same fields on the same form) for each question and enters it into a different row in the table, this code will not work, but it must be fairly close
Private Sub cmdSaveClose_Click()
Dim x As Integer
Dim i As Integer
x = MsgBox("Are you sure you want to save changes?", 4, "Exit?")
'VbNo constant throws back #7
'VbYes constant throws back #6
If x = 7 Then
Exit Sub
Else
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
For i = 1 To 45
db.Execute " INSERT INTO [tblChecklistAnswer]" & "([Answer], [Response]) VALUES " _
& "('" & Me.txtAnswer(i) & "'," & "'" & Me.cmbResponse(i) & "'" & ");"
Next i
DoCmd.Close
End If
End Sub
My problem being that for each input text box it is called txtAnswer1 , txtAnswer2, etc up to txtAnswer45 in this example
and cmbResponse1, cmbResponse2, etc up to cmbResponse45
This is obviously not a method and maybe needs to be converted to a string, help is appreciated I don't particularly want to type the same formula out 45 times so a for loop is desirable
I get compile error & "('" & Me.txtAnswer(i) & "'," & "'" & Me.cmbResponse(i) & "'" & ");"
method or data member not found
thanks