-
Hello All,
I am new to Visual Basic. I am perform error checking for list boxes. How do I check for a value that is already in the list box. Example Message Box: "You have already select this value" The value is already listed in the list box. Thanks, for your help.
-
you can loop through the list items to check for duplicates. Add the following to a Form with a ListBox, TextBox and CommandButton.
Code:
Function CheckListBox(lst As ListBox, sString As String) As Boolean
CheckListBox = True
For I = 0 To lst.ListCount
If lst.List(I) = sString Then CheckListBox = False
Next I
End Function
Private Sub Command1_Click()
If CheckListBox(List1, Text1) Then List1.AddItem Text1
End Sub
Enter something in the TextBox and press the Button. If it's not a duplicate, then it will be added else it will not be added.
-
Thanks, Megatron
Do you (or anybody else) know of a way to check for duplicate values in a listbox without using a command button? My program is design whereas a user double-click on a calendar and the date is put in a listbox. The error checking should occur if the user select that same date twice. I am working with an Access 97 database.
Thanks again!!
-
just put the command1_click event under the dblclick event of the calander control. then everytime you double click on the calender the function fires.