Just thought I'd post back to let you know that I finally got it to work as I
needed it to. Below is the code that finally did the job.
'read the ProductID for the selected Product
Dim lngProductID As Long
lngProductID = Me.lstProducts.Column(0)
Dim strMsg As String
Dim varSelCnt
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant
'check to see if that Product is already on the list
varRecCnt = DCount("ItemID", "tblNextList", "ProductID = " & lngProductID &
"")
If varRecCnt > 0 Then
varSelCnt = Me.lstProducts.ItemsSelected.Count
If varSelCnt > 0 Then
strMsg = "That produce it already in the Grocery List"
MsgBox strMsg, vbInformation + vbOKOnly, "Duplicated Product"
'Me.lstProducts.Selected(varSelCnt) = False
'add all selected products to the Grocery List
Set frm = Forms!frmNeedsList
Set ctl = frm!lstProducts
For Each varItm In ctl.ItemsSelected
If ctl.ItemData(varItm) = lngProductID Then
Me.lstProducts.Selected(varItm) = False
End If
Next varItm
End If
End If
I actaully had to iterate through each of the items in the list, checking
each item to see if that was the item that contained the ProductID that I had
captured to a variable in the OnClick event of the control. The code that
really does the trick is:
For Each varItm In ctl.ItemsSelected
If ctl.ItemData(varItm) = lngProductID Then
Me.lstProducts.Selected(varItm) = False
End If
Next varItm
The only reason that I posted this back was so that in the event that anyone
else every needed to accomplish something like this, perhaps they would not
have to spend as much time figuring it out as I did.
Doug, thanks so much for all your help. You have helped me many times. Just
doing a search in the newsgroups for something I need to know about will most
times help me accomplish the task. Your postings, along with the many others
who attempt to help with their postings, are really appreciated by many of us
who frequent these newsgroups.
Mr B