Looping through List box

Dirtrider929

Registered User.
Local time
Yesterday, 19:38
Joined
Nov 12, 2013
Messages
32
I have some code that loops through a list box to add values selected to a table and it is getting stuck where I think it should be working, "For I = 0 To lstScan_Items.ListCount - 1".

Can anyone point out where the error is? I have been stuck for a few hours.

Private Sub btnScan_Add_Item_Click()
If IsNull(Me.txtOFFER_ID) Then

Dim msg
msg = MsgBox("You must enter scan information above before adding products", vbCritical, "Application Error")

Else

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim I As Integer, db As Database, rec As Recordset
Set db = CurrentDb
Set rec = db.OpenRecordset("tblSLRScanItems", dbOpenDynaset)

'Add SKU's by looping through the items listbox
For I = 0 To lstScan_Items.ListCount - 1
If lstScan_Items.Selected(I) Then
With rec
.AddNew
!OfferID = txtOFFER_ID
!ItemID = lstScan_Items.Column(0, I)
!ItemDescription = lstScan_Items.Column(1, I)
.Update
End With
End If
Next I
Me.Refresh
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom