I have the following code on a button control on a subform:
Dim db As Database: Set db = CurrentDb
Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim SQLstr As String
Set frm = Forms![frmQuestionaire]![frmQuestions]![frmResponses Subform].Form
Set ctl = frm!ListRspns
For Each varItem In Me.ListRspns.ItemsSelected
SQLstr = "INSERT INTO tblResponses(ResponseDate, QstnID, AssociateRef, Rspns) " _
& "SELECT #" & Me.ResponseDate & "#, " & Me.QstnID & ", ' " & Me.AssociateRef & " ', " _
& "'" & ctl.ItemData(varItem) & "';"
Debug.Print SQLstr
db.Execute SQLstr
CurrentDb.TableDefs.Refresh
DoEvents
Next varItem
DoCmd.GoToRecord , , acNewRec
Forms![frmQuestionaire]![frmQuestions].Form![Command38].SetFocus
SendKeys "~"
[Command38] is a button control on the main form that is for the next question in the series.
My problem is that whenever the selections are saved using the code above, Access adds the items selected, but also adds a blank record.
Any suggestions? Thoughts?
Dim db As Database: Set db = CurrentDb
Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim SQLstr As String
Set frm = Forms![frmQuestionaire]![frmQuestions]![frmResponses Subform].Form
Set ctl = frm!ListRspns
For Each varItem In Me.ListRspns.ItemsSelected
SQLstr = "INSERT INTO tblResponses(ResponseDate, QstnID, AssociateRef, Rspns) " _
& "SELECT #" & Me.ResponseDate & "#, " & Me.QstnID & ", ' " & Me.AssociateRef & " ', " _
& "'" & ctl.ItemData(varItem) & "';"
Debug.Print SQLstr
db.Execute SQLstr
CurrentDb.TableDefs.Refresh
DoEvents
Next varItem
DoCmd.GoToRecord , , acNewRec
Forms![frmQuestionaire]![frmQuestions].Form![Command38].SetFocus
SendKeys "~"
[Command38] is a button control on the main form that is for the next question in the series.
My problem is that whenever the selections are saved using the code above, Access adds the items selected, but also adds a blank record.
Any suggestions? Thoughts?