Help! trying to insert data into a table
Private Sub cmdAdd_Click()
Dim rs as new ADODB.recordsetI have two list boxes called "lstdates" which contain 600 dates and a list box called "lstboats" which contain 60 boat names, i want to be able to select multiple dates and multiple boats and insert them into a table called tblboatstodates fieldss boatid and checkdateid, the following code:
Dim varBoatID
Dim varCheckDateID
rs.Open "tblBoatstoDates", CurrentProject.Connection, adOpenStatic, adLockOptimistic
For Each varBoatID In lstBoats.ItemsSelected
For Each varCheckDateID In lstDates.ItemsSelected
rs.AddNew
rs!BoatID = varBoatID
rs!Checkdateid = varCheckDateID
rs.Update
Next
Next
rs.Close
End Sub
the code works but is inputting the order they appear
Example: say if i had 10 dates in the list box"lstdates" ranging from 01 Jan 04 -- 10 Jan 04
(this dates come from a table called tblcheckdate1 and the unique key is DateID)
01 Jan 04 = DATEID 26
02 Jan 04 = DATEID 27
03 Jan 04 = DATEID 28
04 Jan 04 = DATEID 29
05 Jan 04 = DATEID 30
06 Jan 04 = DATEID 31
..etc
BUT as 01 Jan 04 appears first in the list its value =0 when inputting into tblboatstodates
02 Jan 04 =1
03 Jan 04 =2
this is the same for lstboats
|