PC Review


Reply
Thread Tools Rate Thread

ComboBox Query

 
 
Blobbies
Guest
Posts: n/a
 
      19th Apr 2008
I have a number of comboboxes on a userform.

They share a common prefix in their name and are then numbered i.e. cbx1,
cbx2, cbx3 etc.

I want to run a For .... Next procedure with these comboboxes, and am
wondering how to refer to them within this procedure - i.e "cbx" & (whatever
number - starting at 1 through to 10)

Is this possible?

Thanking you in advance!



Edi
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      19th Apr 2008
Option Explicit
Private Sub CommandButton1_Click()
Dim ctrl As Control
Dim iCtr As Long
For iCtr = 1 To 10
Set ctrl = Me.Controls("cbx" & iCtr)
'do what you want???
'clear the combobox
ctrl.ListIndex = -1
Next iCtr
End Sub

You could also loop through the controls and work on just the comboboxes.

Option Explicit
Private Sub CommandButton1_Click()
Dim ctrl As Control
For each ctrl in me.controls
if typeof ctrl is msforms.combobox then
ctrl.listindex = -1
end if
next ctrl
End Sub


Blobbies wrote:
>
> I have a number of comboboxes on a userform.
>
> They share a common prefix in their name and are then numbered i.e. cbx1,
> cbx2, cbx3 etc.
>
> I want to run a For .... Next procedure with these comboboxes, and am
> wondering how to refer to them within this procedure - i.e "cbx" & (whatever
> number - starting at 1 through to 10)
>
> Is this possible?
>
> Thanking you in advance!
>
> Edi


--

Dave Peterson
 
Reply With Quote
 
Blobbies
Guest
Posts: n/a
 
      19th Apr 2008
Thank you Dave!! I was close in my trial and error attempts, but I'm not
sure whether I would have got there in the end or not!!!



Edi

"Dave Peterson" wrote:

> Option Explicit
> Private Sub CommandButton1_Click()
> Dim ctrl As Control
> Dim iCtr As Long
> For iCtr = 1 To 10
> Set ctrl = Me.Controls("cbx" & iCtr)
> 'do what you want???
> 'clear the combobox
> ctrl.ListIndex = -1
> Next iCtr
> End Sub
>
> You could also loop through the controls and work on just the comboboxes.
>
> Option Explicit
> Private Sub CommandButton1_Click()
> Dim ctrl As Control
> For each ctrl in me.controls
> if typeof ctrl is msforms.combobox then
> ctrl.listindex = -1
> end if
> next ctrl
> End Sub
>
>
> Blobbies wrote:
> >
> > I have a number of comboboxes on a userform.
> >
> > They share a common prefix in their name and are then numbered i.e. cbx1,
> > cbx2, cbx3 etc.
> >
> > I want to run a For .... Next procedure with these comboboxes, and am
> > wondering how to refer to them within this procedure - i.e "cbx" & (whatever
> > number - starting at 1 through to 10)
> >
> > Is this possible?
> >
> > Thanking you in advance!
> >
> > Edi

>
> --
>
> 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
combobox in query MAANI Microsoft Access Queries 2 5th Nov 2009 03:02 PM
Query for use in combobox benjaminkmartin@gmail.com Microsoft Access Queries 5 7th Aug 2008 10:25 PM
Need help with a combobox query Ronald Marchand Microsoft Access Queries 12 11th Sep 2007 12:21 PM
Combobox query? Greg B Microsoft Excel Programming 2 14th Mar 2006 12:35 AM
Combobox Query =?Utf-8?B?TWF4aW1lIE1hdWdlYWlz?= Microsoft Excel Programming 1 17th Nov 2004 11:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:48 AM.