[AccessD] Access 97 question. Preventing a duplicate value frombeing added to a listbox

Gustav Brock Gustav at cactus.dk
Mon Apr 25 07:44:53 CDT 2005


Hi BL

Include Chr(34) in your search/checking: Chr$(34) & aString & Chr$(34)

/gustav

>>> boogieloogie at gmail.com 04/25 2:15 pm >>>
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




More information about the AccessD mailing list