PC Review


Reply
Thread Tools Rate Thread

Custom Form: Copy from one list box to another

 
 
StumpedAgain
Guest
Posts: n/a
 
      28th Jul 2008
I am creating a custom form and have two listboxes: source and target. I
want the users to be able to select a product in the source listbox and click
the "Add" button that takes that selection and adds it to the target listbox.
I tried the following to no avail:

Private Sub AddButton_Click()
'Adds whatever is selected in the Source listbox to the Target listbox
With LB_Target
.AddItem LB_Source.Selected '<-Compile Error: Argument not optional
End With

End Sub

Any suggestions/insights?

Thanks.
--
-SA
 
Reply With Quote
 
 
 
 
Leith Ross
Guest
Posts: n/a
 
      28th Jul 2008
On Jul 28, 10:32 am, StumpedAgain
<StumpedAg...@discussions.microsoft.com> wrote:
> I am creating a custom form and have two listboxes: source and target. I
> want the users to be able to select a product in the source listbox and click
> the "Add" button that takes that selection and adds it to the target listbox.
> I tried the following to no avail:
>
> Private Sub AddButton_Click()
> 'Adds whatever is selected in the Source listbox to the Target listbox
> With LB_Target
> .AddItem LB_Source.Selected '<-Compile Error: Argument not optional
> End With
>
> End Sub
>
> Any suggestions/insights?
>
> Thanks.
> --
> -SA


Hello StumpedAgain,

You need to use the current index of the source list box. The Selected
property is used with List Boxes that have the MultiSelect property
set. It takes a index number like this... LB_Source(1). You can then
test it to see if the return value is True or False. Here is what you
need...

Private Sub AddButton_Click()

With LB_Target
.AddItem LB_Source.Value
End With

End Sub

Sincerely,
Leith Ross

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      28th Jul 2008
Somthing like this

Private Sub CommandButton1_Click()
With ListBox1
If .Value <> "" Then
ListBox2.AddItem .Value
End If
End With
End Sub

"StumpedAgain" wrote:

> I am creating a custom form and have two listboxes: source and target. I
> want the users to be able to select a product in the source listbox and click
> the "Add" button that takes that selection and adds it to the target listbox.
> I tried the following to no avail:
>
> Private Sub AddButton_Click()
> 'Adds whatever is selected in the Source listbox to the Target listbox
> With LB_Target
> .AddItem LB_Source.Selected '<-Compile Error: Argument not optional
> End With
>
> End Sub
>
> Any suggestions/insights?
>
> Thanks.
> --
> -SA

 
Reply With Quote
 
StumpedAgain
Guest
Posts: n/a
 
      28th Jul 2008
The If thing didn't work, but I modified to the following to get it to work:

Private Sub AddButton_Click()
'Adds whatever is selected in the Source listbox to the Target listbox
With LB_Target
.AddItem LB_Source.Value
End With

End Sub

Thanks
--
-SA


"Office_Novice" wrote:

> Somthing like this
>
> Private Sub CommandButton1_Click()
> With ListBox1
> If .Value <> "" Then
> ListBox2.AddItem .Value
> End If
> End With
> End Sub
>
> "StumpedAgain" wrote:
>
> > I am creating a custom form and have two listboxes: source and target. I
> > want the users to be able to select a product in the source listbox and click
> > the "Add" button that takes that selection and adds it to the target listbox.
> > I tried the following to no avail:
> >
> > Private Sub AddButton_Click()
> > 'Adds whatever is selected in the Source listbox to the Target listbox
> > With LB_Target
> > .AddItem LB_Source.Selected '<-Compile Error: Argument not optional
> > End With
> >
> > End Sub
> >
> > Any suggestions/insights?
> >
> > Thanks.
> > --
> > -SA

 
Reply With Quote
 
StumpedAgain
Guest
Posts: n/a
 
      28th Jul 2008
Another add-on question:

If a user selects the product and adds it, how do I remove it from the
origination listbox so that they can't select it more than once? I tried the
following but however I seem to try it, I can only remove the first entry in
the listbox, not the currently selected entry:

Private Sub AddButton_Click()
'Adds whatever is selected in the Source listbox to the Target listbox
With LB_Target
.AddItem LB_Source.Value
End With

'Removes the selected from the Source list so that it cannot be selected
more than once
With LB_Source
.RemoveItem Selected.Count
End With

End Sub
--
-SA


"StumpedAgain" wrote:

> I am creating a custom form and have two listboxes: source and target. I
> want the users to be able to select a product in the source listbox and click
> the "Add" button that takes that selection and adds it to the target listbox.
> I tried the following to no avail:
>
> Private Sub AddButton_Click()
> 'Adds whatever is selected in the Source listbox to the Target listbox
> With LB_Target
> .AddItem LB_Source.Selected '<-Compile Error: Argument not optional
> End With
>
> End Sub
>
> Any suggestions/insights?
>
> Thanks.
> --
> -SA

 
Reply With Quote
 
StumpedAgain
Guest
Posts: n/a
 
      28th Jul 2008
Thanks! Do you happen to know how to remove the selected item from a
listbox? I can remove the first item (and have done so in multiple ways),
but can't seem to remove whichever is selected using a button. I tried
variations of the following with no result:

With LB_Source
.RemoveItem LB_Source(Selected)
End With

--
-SA


"Leith Ross" wrote:

> On Jul 28, 10:32 am, StumpedAgain
> <StumpedAg...@discussions.microsoft.com> wrote:
> > I am creating a custom form and have two listboxes: source and target. I
> > want the users to be able to select a product in the source listbox and click
> > the "Add" button that takes that selection and adds it to the target listbox.
> > I tried the following to no avail:
> >
> > Private Sub AddButton_Click()
> > 'Adds whatever is selected in the Source listbox to the Target listbox
> > With LB_Target
> > .AddItem LB_Source.Selected '<-Compile Error: Argument not optional
> > End With
> >
> > End Sub
> >
> > Any suggestions/insights?
> >
> > Thanks.
> > --
> > -SA

>
> Hello StumpedAgain,
>
> You need to use the current index of the source list box. The Selected
> property is used with List Boxes that have the MultiSelect property
> set. It takes a index number like this... LB_Source(1). You can then
> test it to see if the return value is True or False. Here is what you
> need...
>
> Private Sub AddButton_Click()
>
> With LB_Target
> .AddItem LB_Source.Value
> End With
>
> End Sub
>
> Sincerely,
> Leith Ross
>
>

 
Reply With Quote
 
StumpedAgain
Guest
Posts: n/a
 
      28th Jul 2008
After scouring google, I finally found a solution that deletes the selected
entry in a list box:

Dim i As Long
With LB_Source
For i = 0 To LB_Source.ListCount - 1
If LB_Source.Selected(i) Then
.RemoveItem (i)
End If
Next i
End With
--
-SA


"StumpedAgain" wrote:

> Thanks! Do you happen to know how to remove the selected item from a
> listbox? I can remove the first item (and have done so in multiple ways),
> but can't seem to remove whichever is selected using a button. I tried
> variations of the following with no result:
>
> With LB_Source
> .RemoveItem LB_Source(Selected)
> End With
>
> --
> -SA
>
>
> "Leith Ross" wrote:
>
> > On Jul 28, 10:32 am, StumpedAgain
> > <StumpedAg...@discussions.microsoft.com> wrote:
> > > I am creating a custom form and have two listboxes: source and target. I
> > > want the users to be able to select a product in the source listbox and click
> > > the "Add" button that takes that selection and adds it to the target listbox.
> > > I tried the following to no avail:
> > >
> > > Private Sub AddButton_Click()
> > > 'Adds whatever is selected in the Source listbox to the Target listbox
> > > With LB_Target
> > > .AddItem LB_Source.Selected '<-Compile Error: Argument not optional
> > > End With
> > >
> > > End Sub
> > >
> > > Any suggestions/insights?
> > >
> > > Thanks.
> > > --
> > > -SA

> >
> > Hello StumpedAgain,
> >
> > You need to use the current index of the source list box. The Selected
> > property is used with List Boxes that have the MultiSelect property
> > set. It takes a index number like this... LB_Source(1). You can then
> > test it to see if the return value is True or False. Here is what you
> > need...
> >
> > Private Sub AddButton_Click()
> >
> > With LB_Target
> > .AddItem LB_Source.Value
> > End With
> >
> > End Sub
> >
> > Sincerely,
> > Leith Ross
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to copy a bulleted list with its custom bullets? Tony Microsoft Powerpoint 1 24th Nov 2009 10:23 PM
How to save a list of custom words in a rule to a text file, or to copy the list? Dmitriy Kopnichev Microsoft Outlook 3 26th Jan 2004 06:15 AM
How to save a list of custom words in a rule to a text file, or to copy the list? Dmitriy Kopnichev Microsoft Outlook Third-Party Utilities 3 26th Jan 2004 06:15 AM
How to save a list of custom words in a rule to a text file, or to copy the list? Dmitriy Kopnichev Microsoft Outlook Discussion 3 26th Jan 2004 06:15 AM
How do I copy custom form and master category list to another computer Jain Sajer Microsoft Outlook 1 16th Dec 2003 06:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:17 PM.