I have some code that adds new records into a table for each ID in a list
box when a button on a form is clicked. This works fine. My problem now is
that I wish to be able to edit all the records for people whose ID is in the
list box. I made minor changes to the code (mainly replacing rs.AddNew with
rs.Edit)and it appears to be updating only the first record and then
overwriting that record with the next, etc until it runs out of ID's in the
list box. In other words, it is stepping through the ID's in the list box,
but not the records. Is there a trick to this? I have spent many hours
doing minor changes and still have the same problem.
The code follows (I have reduced the number of fields I am updating to keep
the size of the message down).
Dim intIndex As Integer
For intIndex = 0 To Me.lboBulkList. ListCount
Me.lbo.BulkList .Selected(intIn dex) = True
Next intIndex
Dim db As Database
Dim rs As Recordset
Dim prm As Parameter
Dim qdf As QueryDef
Set db = CurrentDb()
Set qdf = db.QueryDefs("q ryBulkEdit")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecords et(dbOpenDynase t)
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant
Set frm = Forms!frmExcurs ions
Set ctl = frm! lboBulkList
For Each varItm In ctl.ItemsSelect ed
rs.Edit
rs(0) = Me. lboBulkList.Ite mData(varItm)
rs!Date = frm!txtDate
rs!Faculty = frm!cboFaculty
rs!Course = frm!Course
rs!Cost = frm!ExCost
rs.Update
Next varItm
rs.Close: Set rs = Nothing
dixie
box when a button on a form is clicked. This works fine. My problem now is
that I wish to be able to edit all the records for people whose ID is in the
list box. I made minor changes to the code (mainly replacing rs.AddNew with
rs.Edit)and it appears to be updating only the first record and then
overwriting that record with the next, etc until it runs out of ID's in the
list box. In other words, it is stepping through the ID's in the list box,
but not the records. Is there a trick to this? I have spent many hours
doing minor changes and still have the same problem.
The code follows (I have reduced the number of fields I am updating to keep
the size of the message down).
Dim intIndex As Integer
For intIndex = 0 To Me.lboBulkList. ListCount
Me.lbo.BulkList .Selected(intIn dex) = True
Next intIndex
Dim db As Database
Dim rs As Recordset
Dim prm As Parameter
Dim qdf As QueryDef
Set db = CurrentDb()
Set qdf = db.QueryDefs("q ryBulkEdit")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecords et(dbOpenDynase t)
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant
Set frm = Forms!frmExcurs ions
Set ctl = frm! lboBulkList
For Each varItm In ctl.ItemsSelect ed
rs.Edit
rs(0) = Me. lboBulkList.Ite mData(varItm)
rs!Date = frm!txtDate
rs!Faculty = frm!cboFaculty
rs!Course = frm!Course
rs!Cost = frm!ExCost
rs.Update
Next varItm
rs.Close: Set rs = Nothing
dixie
Comment