PC Review


Reply
Thread Tools Rate Thread

add combox with code

 
 
Dawna
Guest
Posts: n/a
 
      23rd Nov 2009
Good Morning,

Could someone help with a code to add a combobox to a userform using code.
I'd like to have a command button "add" which will add this combobox.

Thanks in advance.
Dawna
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Nov 2009
How about an alternative...

Add your combobox to the userform while you're in design mode--but hide it and
show it using the commandbutton.

It makes things lots easier.

Dawna wrote:
>
> Good Morning,
>
> Could someone help with a code to add a combobox to a userform using code.
> I'd like to have a command button "add" which will add this combobox.
>
> Thanks in advance.
> Dawna


--

Dave Peterson
 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      23rd Nov 2009
Dawna

You've got two main choices :

1. Add the combobox in your design, but make it Visible = False. When the
time comes during your code use
MyForm.MyCombo.Visible = True

2. Add the combobox using vba code.
This falls into two bits
a. Add the combobox
b. Fill it with your data

The downside of 2 is that you'll need to make sure it doesn't get placed
over other controls.

If you want more info on 2, post a reply.

"Dawna" wrote:

> Good Morning,
>
> Could someone help with a code to add a combobox to a userform using code.
> I'd like to have a command button "add" which will add this combobox.
>
> Thanks in advance.
> Dawna

 
Reply With Quote
 
Dawna
Guest
Posts: n/a
 
      23rd Nov 2009
Hi Paul. Thank you for the reply. Could you help with code for the second
choice?
Thank you again.
Dawna

"Paul" wrote:

> Dawna
>
> You've got two main choices :
>
> 1. Add the combobox in your design, but make it Visible = False. When the
> time comes during your code use
> MyForm.MyCombo.Visible = True
>
> 2. Add the combobox using vba code.
> This falls into two bits
> a. Add the combobox
> b. Fill it with your data
>
> The downside of 2 is that you'll need to make sure it doesn't get placed
> over other controls.
>
> If you want more info on 2, post a reply.
>
> "Dawna" wrote:
>
> > Good Morning,
> >
> > Could someone help with a code to add a combobox to a userform using code.
> > I'd like to have a command button "add" which will add this combobox.
> >
> > Thanks in advance.
> > Dawna

 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      23rd Nov 2009
This should add your box :

Private Sub Create_Combo()
Dim MyCombo As MSforms.ComboBox
Set MyListBox = MyForm.Controls.Add("Forms.ComboBox.1")
With MyListBox
.Top = 10
.Left = 20
.Height = 50
.Name = "myBox"
End With

End Sub

Then to add some data :

Sub Add_Combo_Data()
dim myArray(Number_of_Items)
' Add the items for your list into the array as follows :
For nCount = 1 to Number_of_Items
myArray(nCount) = Whatever ' each of your items
Next
MyNewForm.MyBox.List = myArray

End Sub

You can get very clever with more columns, but positioning becomes seriously
more difficult.

Hope that helps get you started.

"Dawna" wrote:

> Hi Paul. Thank you for the reply. Could you help with code for the second
> choice?
> Thank you again.
> Dawna
>
> "Paul" wrote:
>
> > Dawna
> >
> > You've got two main choices :
> >
> > 1. Add the combobox in your design, but make it Visible = False. When the
> > time comes during your code use
> > MyForm.MyCombo.Visible = True
> >
> > 2. Add the combobox using vba code.
> > This falls into two bits
> > a. Add the combobox
> > b. Fill it with your data
> >
> > The downside of 2 is that you'll need to make sure it doesn't get placed
> > over other controls.
> >
> > If you want more info on 2, post a reply.
> >
> > "Dawna" wrote:
> >
> > > Good Morning,
> > >
> > > Could someone help with a code to add a combobox to a userform using code.
> > > I'd like to have a command button "add" which will add this combobox.
> > >
> > > Thanks in advance.
> > > Dawna

 
Reply With Quote
 
Dawna
Guest
Posts: n/a
 
      24th Nov 2009
Thank you for the help! Much appreciated.

"Paul" wrote:

> This should add your box :
>
> Private Sub Create_Combo()
> Dim MyCombo As MSforms.ComboBox
> Set MyListBox = MyForm.Controls.Add("Forms.ComboBox.1")
> With MyListBox
> .Top = 10
> .Left = 20
> .Height = 50
> .Name = "myBox"
> End With
>
> End Sub
>
> Then to add some data :
>
> Sub Add_Combo_Data()
> dim myArray(Number_of_Items)
> ' Add the items for your list into the array as follows :
> For nCount = 1 to Number_of_Items
> myArray(nCount) = Whatever ' each of your items
> Next
> MyNewForm.MyBox.List = myArray
>
> End Sub
>
> You can get very clever with more columns, but positioning becomes seriously
> more difficult.
>
> Hope that helps get you started.
>
> "Dawna" wrote:
>
> > Hi Paul. Thank you for the reply. Could you help with code for the second
> > choice?
> > Thank you again.
> > Dawna
> >
> > "Paul" wrote:
> >
> > > Dawna
> > >
> > > You've got two main choices :
> > >
> > > 1. Add the combobox in your design, but make it Visible = False. When the
> > > time comes during your code use
> > > MyForm.MyCombo.Visible = True
> > >
> > > 2. Add the combobox using vba code.
> > > This falls into two bits
> > > a. Add the combobox
> > > b. Fill it with your data
> > >
> > > The downside of 2 is that you'll need to make sure it doesn't get placed
> > > over other controls.
> > >
> > > If you want more info on 2, post a reply.
> > >
> > > "Dawna" wrote:
> > >
> > > > Good Morning,
> > > >
> > > > Could someone help with a code to add a combobox to a userform using code.
> > > > I'd like to have a command button "add" which will add this combobox.
> > > >
> > > > Thanks in advance.
> > > > Dawna

 
Reply With Quote
 
Dawna
Guest
Posts: n/a
 
      24th Nov 2009
Thank you as well Dave.

"Dave Peterson" wrote:

> How about an alternative...
>
> Add your combobox to the userform while you're in design mode--but hide it and
> show it using the commandbutton.
>
> It makes things lots easier.
>
> Dawna wrote:
> >
> > Good Morning,
> >
> > Could someone help with a code to add a combobox to a userform using code.
> > I'd like to have a command button "add" which will add this combobox.
> >
> > Thanks in advance.
> > Dawna

>
> --
>
> Dave Peterson
> .
>

 
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
Filter a combox based on selection from another combox David Microsoft Access Form Coding 2 22nd Jan 2010 12:05 AM
Combox Help! PumaMan Microsoft Excel Programming 2 18th Mar 2009 06:00 PM
ADO code with combox box gives errors Rod Microsoft Outlook Form Programming 2 13th Nov 2008 07:28 PM
Combox box in SQL code red6000 Microsoft Access 1 15th Jul 2006 08:43 PM
Why ComBox on Every Tab? =?Utf-8?B?RGF2aWQgSGFiZXJjb20=?= Microsoft Access Forms 3 6th Apr 2006 04:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:36 PM.