Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

MsgBox or How to avoid adding a second time

MsgBox or How to avoid adding a second time

MsgBox or How to avoid adding a second time

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.
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 "Item already choosen." and the item will not be added to list2. This is a sample of my code:

Private Sub Addition_Click()

Dim ctlList As Control
Dim ctlList2 As Control
Dim varitem As Variant
Dim strSQL As String

Set ctlList = Me.list1
Set ctlList2 = Me.list2

For Each varitem In ctlList.ItemsSelected
If 'Selected item in list1 is already in list2' Then
MsgBox "Item already choosen."
Exit sub
'Insert item in list2. No problem with this.
End If
Next varitem

End Sub

My problem is that I don't know what could be the condition of my IF instruction. Anyone has ideas?

Any help is welcome,

RE: MsgBox or How to avoid adding a second time

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.

RE: MsgBox or How to avoid adding a second time

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.
All I want is a msg box who will indicate that the selected item already exists inlist2. Is it possible?

Thanks in advance for your help,

RE: MsgBox or How to avoid adding a second time


You don't need to add "live" data to the list box.  You can step through a recordset and get the data and then add it to your list1.  Then it doesn't matter if the data is removed.

Let us know if you want details or check out the Knowledge Base article Elizabeth mentioned above, it's Q177117.



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close