Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox Value added to a Table

Status
Not open for further replies.

BradB

MIS
Jun 21, 2001
237
US
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


 
Still doesn't work, but I think I found something else. When I comment out the Do While/Loop, it returns the error,"No Current Record. Runtime error '3021"

any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top