Hi
I have 2 date fields (date1 and date2)and 3 listbox (Listb1, LIstb2, and ListB3) in an ACCESS form.
What I am trying to do is select dates in the date fields, select 2 items from each listbox and trying to save it to a table. I need the date1,Listb1 item1, Listb2 item1 and Listb3 item1 to be saved as one record and date2,Listb1 item2, Listb2 item2 and Listb3 item2 to be saved as another record.
The code I am using is as below:
But this code is not doing the way I want it. Any help will be appreciated. Thank you
I have 2 date fields (date1 and date2)and 3 listbox (Listb1, LIstb2, and ListB3) in an ACCESS form.
What I am trying to do is select dates in the date fields, select 2 items from each listbox and trying to save it to a table. I need the date1,Listb1 item1, Listb2 item1 and Listb3 item1 to be saved as one record and date2,Listb1 item2, Listb2 item2 and Listb3 item2 to be saved as another record.
The code I am using is as below:
Code:
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tbl", dbOpenDynaset)
With rs
For Each varItem In Me.Listb1.ItemsSelected
Dim Sdate1 As Date
Dim edate1 As Date
Dim n As Date
Dim c As Long
Sdate1 = Me.date1
edate1 = Me.date2
For n = Sdate1 To edate1
c = c + 1
rs.AddNew
rs!StartDate = Me.date1
rs!EndDate = Me.date2
rs!Listb1item1 = Me.Listb1.ItemData(varItem)
rs!istb2item1 = Me.listb2.Column(0)
rs!lstb3item1 = Me.listb3.Column(0)
rs!rptfld = Me.Listb1.ItemData(varItem) 'this is another field to hold the same data of rs!Listb1item1
rs.Update
Next n
Next varItem
End With
rs.Close
Set rs = Nothing
Comment