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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move item from one list box to another?

Status
Not open for further replies.

gtroiano

Technical User
Nov 7, 2001
99
US
i am trying to creat an address book similar to the one in outlook express. The setup on the main address book form is this:
1. One list box that holds the email addresses. (lstEmail)
2. One list box for "To:" (ToBox)
3. One command button that moves the email address
from "lstEmail" to "ToBox" without removing it from the first list box. (CmdTo)
if you look at the
4. One command button that opens a data entry form for new contacts. (CmdNew)

in outlook express, if you click on the "To:" label in front of where you would type the email address when composing a new email you can see what i mean.

well, the jist of the problem is that i can't get the email address from the first list box (lstEmail) to go over to the second (ToBox). i got the following code from microsoft but it doesn't seem to work. i always receive "Run-time error 438: Object doesn't support this property of method".

This is the code behind the button to move the email address:
Private Sub CmdTo_Click()
MoveSingleItem "lstEmail", "ToBox"
End Sub


This is the sub routine called above:
Sub MoveSingleItem(strSourceControl As String, strTargetControl As String)

Dim strItem As String
Dim intColumnCount As Integer
For intColumnCount = 0 To Me.Controls(strSourceControl).ColumnCount - 1
strItem = strItem & Me.Controls(strSourceControl).column(intColumnCount) & ";"
Next
strItem = Left(strItem, Len(strItem) - 1)
'Check the length to make sure something is selected
If Len(strItem) > 0 Then
Me.Controls(strTargetControl).AddItem strItem
'<---this is the line that is giving me trouble.
Me.Controls(strSourceControl).RemoveItem Me.Controls(strSourceControl).ListIndex
Else
MsgBox &quot;Please select an item to move.&quot;
End If
End Sub

 
Hi!

Make sure the row source type of the ToBox is Value list, then use the following code on the button click:

If Nz(Len(Me!ToBox.RowSource), 0) = 0 Then
Me!ToBox.RowSource = Me!lstEmail.Value
Else
Me!ToBox.RowSource = Me!ToBox.RowSource & &quot;;&quot; & Me!lstEmail.Value
End If

Please note that this will not set up a recipients list though you will be able to use the RowSource as the recipients list when you set up your email in Outlook.

hth
Jeff Bridgham
bridgham@purdue.edu
 
the code for the command button you suggested returns a type mismatch error. also, i am not sure if i was clear enough with my question. i am not actually using outlook or outlook express; i am just setting up the form to look like it.

jerry
 
Hi jerry!

Could you post your code and indicate the line that the error occurrs at? I'll see if I can figure out what is wrong.
Jeff Bridgham
bridgham@purdue.edu
 
jeff,

thanks. i figured it out. appreciate the help.

jerry.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top