Goal: Add ALL selections from a listbox (StaffID's), DatePicker (Date of a List), and Now() (Date Received) to a database.
When I run the following code, the database isn't updated. Nothing is added to the table. I also don't get an error.
Form
StaffID = listbox
Date of List = DatePicker
Date Received = Now()
Table
ID = Autonumber
StaffID = Number
DateList = Date
DateRec = Date
In the form, I select the "Date of the List". Then, I select which StaffID's are to be added to the listbox. Next, I want to click a CommandButton to add ALL the items in the listbox to be added to the database. The listbox has the StaffID, the DatePicker has the DateList, and I want Today's date to be added to DateRec.
This doesn't work:
Private Sub cmdAdd_Click()
'The form will add all the people selected from the lstStaff listbox
'and add them to the database, and then move on to the next record.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("TestListBoxAdd" ‘Open the Table
Do Until rs.EOF
lstStaff.Value = rs!StaffID
DateList.Value = rs!DateList
Now() = rs!DateRec
rs.Edit
rs.Update
Loop
rs.Close
Set rs = Nothing
End Sub
Brad Boydston
When I run the following code, the database isn't updated. Nothing is added to the table. I also don't get an error.
Form
StaffID = listbox
Date of List = DatePicker
Date Received = Now()
Table
ID = Autonumber
StaffID = Number
DateList = Date
DateRec = Date
In the form, I select the "Date of the List". Then, I select which StaffID's are to be added to the listbox. Next, I want to click a CommandButton to add ALL the items in the listbox to be added to the database. The listbox has the StaffID, the DatePicker has the DateList, and I want Today's date to be added to DateRec.
This doesn't work:
Private Sub cmdAdd_Click()
'The form will add all the people selected from the lstStaff listbox
'and add them to the database, and then move on to the next record.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("TestListBoxAdd" ‘Open the Table
Do Until rs.EOF
lstStaff.Value = rs!StaffID
DateList.Value = rs!DateList
Now() = rs!DateRec
rs.Edit
rs.Update
Loop
rs.Close
Set rs = Nothing
End Sub
Brad Boydston