Hello,
I am new to using recordsets, and i am completly stuck with this one.
I am trying to use a multi select list box to write records to a table.
Something in my code is causing the same record to be written over and
over, for example if I have 4 items selected, it writes the same item 4
times in my table.
Here is my code.
Private Sub OrderRxs_Click()
Dim db As DAO.Database
Dim rstOrder As DAO.Recordset
Dim varItem As Variant
OrderGroupNumber = DMax("[OrderGroupID]", "[RefillOrders_Info]") +
1
If ListBox.ItemsSelected.Count = 0 Then
MsgBox "You must select Rx Numbers to Order.", vbExclamation +
vbOKOnly
Exit Sub
Else
bytChoice1 = MsgBox("Order " & ListBox.ItemsSelected.Count & "
Rx(s) for Paitent?", vbInformation + vbYesNo)
If bytChoice1 = vbNo Then
Exit Sub
End If
If bytChoice1 = vbYes Then
Set db = CurrentDb
Set rstOrder = db.OpenRecordset("RefillOrders_Info")
With rstOrder
For Each varItem In ListBox.ItemsSelected
.AddNew
![OrderGroupID] = OrderGroupNumber
![Patient Code] = ListBox.Column(1)
![Pat Last Name] = ListBox.Column(2)
![Pat First Nme] = ListBox.Column(3)
![EmployeeID] = lngCurrentEmpID
.Update
Next varItem
End With
End If
End If
rstOrder.Close
Set rstOrder = Nothing
db.Close
Set db = Nothing
End Sub
I would love some help with my mess!!!
thanks,
Lisa