M
Matt K.
Why does this code only work on the last item selected in the listbox? I have
a feeling it has to do with opening and closing the recordset????
I am using this on a form that allows the user to update a field (that they
chose from a combobox) for multiple records (they select in the listbox).
For Each itm In Me.lstSurveysForUpdate.ItemsSelected
Set db = CurrentDb
Set rstDestTable = db.OpenRecordset("SELECT " &
Me.cboFieldToUpdate.Column(4) & ".SURVEYid FROM " &
Me.cboFieldToUpdate.Column(4) & _
" WHERE " & Me.cboFieldToUpdate.Column(4) & ".SURVEYid=" &
Me.lstSurveysForUpdate.Column(0), dbOpenDynaset)
If rstDestTable.RecordCount = 0 Then
strAddRecord = "INSERT INTO " & Me.cboFieldToUpdate.Column(4) & "
(SURVEYid) VALUES (" & Me.lstSurveysForUpdate.Column(0) & ")"
db.Execute strAddRecord, dbFailOnError
rstDestTable.Close
Set db = Nothing
Set rstDestTable = Nothing
Else
End If
Next itm
This looks in the "child" table of a one to one relationship (PK=SURVEYid)
to see if there is a related record to even update. If not it INSERTs one to
be updated... the updating code is not pasted here.
I hope this makes sense to someone.
a feeling it has to do with opening and closing the recordset????
I am using this on a form that allows the user to update a field (that they
chose from a combobox) for multiple records (they select in the listbox).
For Each itm In Me.lstSurveysForUpdate.ItemsSelected
Set db = CurrentDb
Set rstDestTable = db.OpenRecordset("SELECT " &
Me.cboFieldToUpdate.Column(4) & ".SURVEYid FROM " &
Me.cboFieldToUpdate.Column(4) & _
" WHERE " & Me.cboFieldToUpdate.Column(4) & ".SURVEYid=" &
Me.lstSurveysForUpdate.Column(0), dbOpenDynaset)
If rstDestTable.RecordCount = 0 Then
strAddRecord = "INSERT INTO " & Me.cboFieldToUpdate.Column(4) & "
(SURVEYid) VALUES (" & Me.lstSurveysForUpdate.Column(0) & ")"
db.Execute strAddRecord, dbFailOnError
rstDestTable.Close
Set db = Nothing
Set rstDestTable = Nothing
Else
End If
Next itm
This looks in the "child" table of a one to one relationship (PK=SURVEYid)
to see if there is a related record to even update. If not it INSERTs one to
be updated... the updating code is not pasted here.
I hope this makes sense to someone.