Boogie Loogie
boogieloogie at gmail.com
Mon Apr 25 07:15:04 CDT 2005
Hello. I have a list box populated with a value list thus no table
involved. I am trying to prevent duplicate values from being added but
thus far have not been able to solve this. The problem is that if I
add a value of 123 to the list I can no longer add 1,2,3,12,or 23.
What am I doing wrong?
Thanks
BL
ACCESS 97 CODE
Private Sub cmdAddPid_Click()
With Me
Beep
If Not IsNull(!txtPID) And !txtPID <> Trim("") Then
Call addItem(!lstPID, Trim(!txtPID))
End If
End With
End Sub
Public Sub addItem(aList As ListBox, aString As String)
Dim i As Long
Dim checking As String
For i = 1 To Len(aList.RowSource) - Len(aString)
checking = Mid(aList.RowSource, i, Len(aString))
If checking = aString Then
If Len(checking) = Len(aString) Then
Exit Sub
End If
End If
Next i
aList.RowSource = aList.RowSource & Chr$(34) & aString & Chr$(34) & ";"
End Sub