|
-
Oct 10th, 2000, 02:52 PM
#1
Thread Starter
New Member
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.
-
Oct 10th, 2000, 03:00 PM
#2
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.
-
Oct 12th, 2000, 06:36 AM
#3
Thread Starter
New Member
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!!
-
Oct 12th, 2000, 06:52 AM
#4
Lively Member
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.
Now, aren't you sorry you didn't just keep on scrolling?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|