Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsgBox or How to avoid adding a second time

Status
Not open for further replies.

Cantor

Programmer
Apr 27, 2000
28
0
0
CA
Hi,<br>I've two list box, list1 and list2. When a user selects an item from list1 and click on a command button, the item is added to list2, without be delete from list1. No problem with that. <br>What I want to do now is when the user will tries to add item from list1 a second time, a message box will pop up to say something like &quot;Item already choosen.&quot; and the item will not be added to list2. This is a sample of my code:<br><b><br>Private Sub Addition_Click()<br><br>Dim ctlList As Control<br>Dim ctlList2 As Control<br>Dim varitem As Variant<br>Dim strSQL As String<br><br>Set ctlList = Me.list1<br>Set ctlList2 = Me.list2<br><br>For Each varitem In ctlList.ItemsSelected<br>If <i>'Selected item in list1 is already in list2'</i> Then<br>MsgBox &quot;Item already choosen.&quot;<br>Exit sub<br>Else<br>'Insert item in list2. No problem with this.<br>End If<br>Next varitem<br><br>End Sub<br></b><br>My problem is that I don't know what could be the condition of my IF instruction. Anyone has ideas?<br><br>Any help is welcome,<br>Frank <br>
 
Why don't you remove the selected item from list 1 instead. This is how it's done in the wizards, so it will be more familiar. There is an entire article in the MS Knowledge Base on creating this type of wizard, BTW.
 
I know how to remove the selected item from list1 but I don't want because datas from list1 come from my main table and I need them for other things. I could create another table for only datas who are in list1, but I don't want because, I've many list box and I would be overloaded by the number of table. <br>All I want is a msg box who will indicate that the selected item already exists inlist2. Is it possible?<br><br>Thanks in advance for your help,<br>Cantor
 
Cantor,<br><br>You don't need to add &quot;live&quot; data to the list box.&nbsp;&nbsp;You can step through a recordset and get the data and then add it to your list1.&nbsp;&nbsp;Then it doesn't matter if the data is removed.<br><br>Let us know if you want details or check out the Knowledge Base article Elizabeth mentioned above, it's Q177117.<br><br>&nbsp;<br><br> <p>Kathryn<br><a href=mailto: > </a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top