address a combobox created by vba

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
I've created a combobox in a userform initialize event.
After creating it and populating it with items successfully, I had some dynamic buttons that when pressed would add text to this combobox.

Here is how I made the combobox in the userform initialize

Code:
Dim cbb As Control
    Set cbb = UserForm3.Controls.Add("Forms.combobox.1")
    With cbb
        .Top = 10
        .Left = 5
        .Height = 40
        .Width = 500
        .Font.Size = 28
        For Each cell In spTY.Range("a2:a" & iRow).Cells
            .AddItem cell.Value
        Next cell
    End With

The question is this. How do I address that combobox in later coding.
I tried "userform3.combobox1.value" but recieve an error saying it can't find the object. Any idea's what I would use in place of "combobox1" to address that combobox?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
that didnt work....
Tried that. Named it cb1
and then tried to refrence it later with "userform3.cb1.value ="
 
Upvote 0
yes that worked. Any idea why the autocomplete for the combobox works for text entered in via keyboard but not for text entered in by my buttons? I have an on screen button keyboard (for a touch screen) that is sending letters to this same combobox. The letters make it there now after your help, but do not trigger suggestions from the autocomplete in the cbobox as they do when typed with the keyboard.
 
Upvote 0
hmm, no, I don't know.
I'm using the MS Accessibility k/b and it spawns the auto-complete suggestions...
 
Upvote 0
i see; I answered the wrong q; try

Controls("cb1").
Tweedle, have any ideas on how to refer to the command buttons created the same way? The private subs created beforehand for them do not seem to be enacted when clicking on the dynamically created buttons.
 
Upvote 0
Hi Jimzd,
Normally in that situation I create the button with code and just show/hide or enable/disable. I've had same/similar issues before - something about the binding between the object and the code that I don't really understand can make the process unreliable.
 
Upvote 0
Thanks for the reply.
I've seen similar posts where the buttons were created beforehand and made visible by the dynamic code and tried that method also. But I can't seem to find a way to get them to move to the new page, only make them visible and move them around on the original page they were created on. If you know how to do this please let me know. I don't mind much which method(s) I use right now to get it done.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,894
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top