PC Review


Reply
Thread Tools Rate Thread

Adding "additional" controls programatically

 
 
What-A-Tool
Guest
Posts: n/a
 
      3rd Mar 2007
I have code which creates a form if required - I am able to add standard
form controls this way, but I would like to add an "additional" control
(progress bar) to my programmatically created form. I can't seem to find any
examples of how to do this.
Could anyone help, please?

Thank You - Sean


 
Reply With Quote
 
 
 
 
Doug Glancy
Guest
Posts: n/a
 
      3rd Mar 2007
Sean,

I haven't done this much but I think something like this - I assume a form
with a button on it. When you click the button another button is added:

Private Sub CommandButton1_Click()
Dim test_button As MSForms.CommandButton
Dim ctl As Control

'look under help for "Add" to get the other bstrProgIDs, but they follow the
form below
Set test_button = Me.Controls.Add(bstrProgID:="Forms.CommandButton.1",
Name:="btnTestButton", Visible:=True)
With test_button
.Caption = "Test Button"
End With
'It looks like you can only set location by recasting it as a generic
control
Set ctl = test_button
With ctl
.Top = 20
.Left = 20
End With
End Sub

John Walkenbach has a whole section on this here:

http://www.j-walk.com/ss/excel/tips/tip76.htm

hth,

Doug

"What-A-Tool" <(E-Mail Removed)> wrote in message
news:3e5Gh.32084$(E-Mail Removed)...
>I have code which creates a form if required - I am able to add standard
>form controls this way, but I would like to add an "additional" control
>(progress bar) to my programmatically created form. I can't seem to find
>any examples of how to do this.
> Could anyone help, please?
>
> Thank You - Sean
>



 
Reply With Quote
 
What-A-Tool
Guest
Posts: n/a
 
      3rd Mar 2007
Thank you for your help , however :
This works fine, as long as the control to add is part of the Forms
control group. I don't believe there is a Forms.Progressbar. How do I add a
control that isn't in this collection?


"Doug Glancy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sean,
>
> I haven't done this much but I think something like this - I assume a form
> with a button on it. When you click the button another button is added:
>
> Private Sub CommandButton1_Click()
> Dim test_button As MSForms.CommandButton
> Dim ctl As Control
>
> 'look under help for "Add" to get the other bstrProgIDs, but they follow
> the form below
> Set test_button = Me.Controls.Add(bstrProgID:="Forms.CommandButton.1",
> Name:="btnTestButton", Visible:=True)
> With test_button
> .Caption = "Test Button"
> End With
> 'It looks like you can only set location by recasting it as a generic
> control
> Set ctl = test_button
> With ctl
> .Top = 20
> .Left = 20
> End With
> End Sub
>
> John Walkenbach has a whole section on this here:
>
> http://www.j-walk.com/ss/excel/tips/tip76.htm
>
> hth,
>
> Doug
>
> "What-A-Tool" <(E-Mail Removed)> wrote in message
> news:3e5Gh.32084$(E-Mail Removed)...
>>I have code which creates a form if required - I am able to add standard
>>form controls this way, but I would like to add an "additional" control
>>(progress bar) to my programmatically created form. I can't seem to find
>>any examples of how to do this.
>> Could anyone help, please?
>>
>> Thank You - Sean
>>

>
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      3rd Mar 2007
If you want a progress bar, as you note there is no built-in control (there
may be commercial controls, but I know of none), but you could just add the
usual type of progress indicator as described here
http://www.enhanceddatasystems.com/E...rogressBar.htm

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"What-A-Tool" <(E-Mail Removed)> wrote in message
news:cc9Gh.42955$(E-Mail Removed)...
> Thank you for your help , however :
> This works fine, as long as the control to add is part of the Forms
> control group. I don't believe there is a Forms.Progressbar. How do I add
> a control that isn't in this collection?
>
>
> "Doug Glancy" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Sean,
>>
>> I haven't done this much but I think something like this - I assume a
>> form with a button on it. When you click the button another button is
>> added:
>>
>> Private Sub CommandButton1_Click()
>> Dim test_button As MSForms.CommandButton
>> Dim ctl As Control
>>
>> 'look under help for "Add" to get the other bstrProgIDs, but they follow
>> the form below
>> Set test_button = Me.Controls.Add(bstrProgID:="Forms.CommandButton.1",
>> Name:="btnTestButton", Visible:=True)
>> With test_button
>> .Caption = "Test Button"
>> End With
>> 'It looks like you can only set location by recasting it as a generic
>> control
>> Set ctl = test_button
>> With ctl
>> .Top = 20
>> .Left = 20
>> End With
>> End Sub
>>
>> John Walkenbach has a whole section on this here:
>>
>> http://www.j-walk.com/ss/excel/tips/tip76.htm
>>
>> hth,
>>
>> Doug
>>
>> "What-A-Tool" <(E-Mail Removed)> wrote in message
>> news:3e5Gh.32084$(E-Mail Removed)...
>>>I have code which creates a form if required - I am able to add standard
>>>form controls this way, but I would like to add an "additional" control
>>>(progress bar) to my programmatically created form. I can't seem to find
>>>any examples of how to do this.
>>> Could anyone help, please?
>>>
>>> Thank You - Sean
>>>

>>
>>

>
>



 
Reply With Quote
 
What-A-Tool
Guest
Posts: n/a
 
      3rd Mar 2007
"Bob Phillips" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If you want a progress bar, as you note there is no built-in control
> (there may be commercial controls, but I know of none), but you could just
> add the usual type of progress indicator as described here
> http://www.enhanceddatasystems.com/E...rogressBar.htm
>
> --
> ---
> HTH
>
> Bob
>


So you are saying there is no way to programatically add the Microsoft
ProgressBar Control, Version 5.0 or Version 6.0, that I have available in
the "Addtional Controls" dialog box accesible from the tools menu? These
controls are contained in comctl32.ocx, or MSCOMCTL.OCX, respectively. Is
there a way to programatically create a reference to 1 of these .ocx files,
and add the control from there?

Thanks Bob -
Sean


 
Reply With Quote
 
Doug Glancy
Guest
Posts: n/a
 
      3rd Mar 2007
Sean,

I don't know how to do what you ask.

I think controls are usurally added at runtime in situations where the exact
number of controls needed is not yet known, for example, one textbox per
record, when the number of records to be entered can't be known at design
time.

If this is not the case with your application. perhaps you could add the
progress bar to the bottom of your form at design time, and just expand the
form during run time when you want the bar to be visible?

just a thought,

Doug

"What-A-Tool" <(E-Mail Removed)> wrote in message
news:BUfGh.49466$(E-Mail Removed)...
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> If you want a progress bar, as you note there is no built-in control
>> (there may be commercial controls, but I know of none), but you could
>> just add the usual type of progress indicator as described here
>> http://www.enhanceddatasystems.com/E...rogressBar.htm
>>
>> --
>> ---
>> HTH
>>
>> Bob
>>

>
> So you are saying there is no way to programatically add the Microsoft
> ProgressBar Control, Version 5.0 or Version 6.0, that I have available in
> the "Addtional Controls" dialog box accesible from the tools menu? These
> controls are contained in comctl32.ocx, or MSCOMCTL.OCX, respectively. Is
> there a way to programatically create a reference to 1 of these .ocx
> files, and add the control from there?
>
> Thanks Bob -
> Sean
>



 
Reply With Quote
 
Andy Pope
Guest
Posts: n/a
 
      3rd Mar 2007
Hi,

This works for me. Adds progress bar to userform and when the form is
clicked will do a simple 1 to 100 prorgess.

Private m_objPBar As Object
Private Sub UserForm_Click()

Dim lngIndex As Long
Dim lngLoop As Long

m_objPBar.Value = 0
For lngIndex = 1 To 100
For lngLoop = 1 To 599999
Next
m_objPBar.Value = m_objPBar.Value + 1
Next

End Sub
Private Sub UserForm_Initialize()

Set m_objPBar = _
Me.Controls.Add("MSComctlLib.ProgCtrl.2", "myProg", True)

With m_objPBar
.Top = 5
.Left = 5
.Width = Me.InsideWidth - 10
.Height = 15
.Value = 0
End With

End Sub

Cheers
Andy

What-A-Tool wrote:
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>>If you want a progress bar, as you note there is no built-in control
>>(there may be commercial controls, but I know of none), but you could just
>>add the usual type of progress indicator as described here
>>http://www.enhanceddatasystems.com/E...rogressBar.htm
>>
>>--
>>---
>>HTH
>>
>>Bob
>>

>
>
> So you are saying there is no way to programatically add the Microsoft
> ProgressBar Control, Version 5.0 or Version 6.0, that I have available in
> the "Addtional Controls" dialog box accesible from the tools menu? These
> controls are contained in comctl32.ocx, or MSCOMCTL.OCX, respectively. Is
> there a way to programatically create a reference to 1 of these .ocx files,
> and add the control from there?
>
> Thanks Bob -
> Sean
>
>

 
Reply With Quote
 
Doug Glancy
Guest
Posts: n/a
 
      3rd Mar 2007
Andy,

Your post reminded me that even though Intellisense doesn't show a property
for a control, e.g., ".top" it might still be available. I do wonder
though, why "top" didn't show for my earlier example of an MSForms.Button,
but did when I cast it as a Control? Anyways, a good reminder not to rely
too much on the IDE features, although generally I'd be lost without them.

Doug

"Andy Pope" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> This works for me. Adds progress bar to userform and when the form is
> clicked will do a simple 1 to 100 prorgess.
>
> Private m_objPBar As Object
> Private Sub UserForm_Click()
>
> Dim lngIndex As Long
> Dim lngLoop As Long
>
> m_objPBar.Value = 0
> For lngIndex = 1 To 100
> For lngLoop = 1 To 599999
> Next
> m_objPBar.Value = m_objPBar.Value + 1
> Next
>
> End Sub
> Private Sub UserForm_Initialize()
>
> Set m_objPBar = _
> Me.Controls.Add("MSComctlLib.ProgCtrl.2", "myProg", True)
>
> With m_objPBar
> .Top = 5
> .Left = 5
> .Width = Me.InsideWidth - 10
> .Height = 15
> .Value = 0
> End With
>
> End Sub
>
> Cheers
> Andy
>
> What-A-Tool wrote:
>> "Bob Phillips" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>
>>>If you want a progress bar, as you note there is no built-in control
>>>(there may be commercial controls, but I know of none), but you could
>>>just add the usual type of progress indicator as described here
>>>http://www.enhanceddatasystems.com/E...rogressBar.htm
>>>
>>>--
>>>---
>>>HTH
>>>
>>>Bob
>>>

>>
>>
>> So you are saying there is no way to programatically add the Microsoft
>> ProgressBar Control, Version 5.0 or Version 6.0, that I have available in
>> the "Addtional Controls" dialog box accesible from the tools menu? These
>> controls are contained in comctl32.ocx, or MSCOMCTL.OCX, respectively. Is
>> there a way to programatically create a reference to 1 of these .ocx
>> files, and add the control from there?
>>
>> Thanks Bob -
>> Sean



 
Reply With Quote
 
Andy Pope
Guest
Posts: n/a
 
      3rd Mar 2007
Hi Doug,

If you go to the Object Browser (F2) and in the libraries dropdown
restrict the search to MSForms you will see the CommandButton does not
appear to have the property Top. I have no idea why but as it's not
exposed here I can understand why intellisense does not know about it.

Cheers
Andy

Doug Glancy wrote:
> Andy,
>
> Your post reminded me that even though Intellisense doesn't show a property
> for a control, e.g., ".top" it might still be available. I do wonder
> though, why "top" didn't show for my earlier example of an MSForms.Button,
> but did when I cast it as a Control? Anyways, a good reminder not to rely
> too much on the IDE features, although generally I'd be lost without them.
>
> Doug
>
> "Andy Pope" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>>Hi,
>>
>>This works for me. Adds progress bar to userform and when the form is
>>clicked will do a simple 1 to 100 prorgess.
>>
>>Private m_objPBar As Object
>>Private Sub UserForm_Click()
>>
>> Dim lngIndex As Long
>> Dim lngLoop As Long
>>
>> m_objPBar.Value = 0
>> For lngIndex = 1 To 100
>> For lngLoop = 1 To 599999
>> Next
>> m_objPBar.Value = m_objPBar.Value + 1
>> Next
>>
>>End Sub
>>Private Sub UserForm_Initialize()
>>
>> Set m_objPBar = _
>>Me.Controls.Add("MSComctlLib.ProgCtrl.2", "myProg", True)
>>
>> With m_objPBar
>> .Top = 5
>> .Left = 5
>> .Width = Me.InsideWidth - 10
>> .Height = 15
>> .Value = 0
>> End With
>>
>>End Sub
>>
>>Cheers
>>Andy
>>
>>What-A-Tool wrote:
>>
>>>"Bob Phillips" <(E-Mail Removed)> wrote in message
>>>news:(E-Mail Removed)...
>>>
>>>
>>>>If you want a progress bar, as you note there is no built-in control
>>>>(there may be commercial controls, but I know of none), but you could
>>>>just add the usual type of progress indicator as described here
>>>>http://www.enhanceddatasystems.com/E...rogressBar.htm
>>>>
>>>>--
>>>>---
>>>>HTH
>>>>
>>>>Bob
>>>>
>>>
>>>
>>>So you are saying there is no way to programatically add the Microsoft
>>>ProgressBar Control, Version 5.0 or Version 6.0, that I have available in
>>>the "Addtional Controls" dialog box accesible from the tools menu? These
>>>controls are contained in comctl32.ocx, or MSCOMCTL.OCX, respectively. Is
>>>there a way to programatically create a reference to 1 of these .ocx
>>>files, and add the control from there?
>>>
>>>Thanks Bob -
>>> Sean

>
>
>

 
Reply With Quote
 
Doug Glancy
Guest
Posts: n/a
 
      3rd Mar 2007
Thanks Andy,

When I looked in the Object Browser, I can see that it's true for the other
MSForms controls as well.

Doug

"Andy Pope" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi Doug,
>
> If you go to the Object Browser (F2) and in the libraries dropdown
> restrict the search to MSForms you will see the CommandButton does not
> appear to have the property Top. I have no idea why but as it's not
> exposed here I can understand why intellisense does not know about it.
>
> Cheers
> Andy
>
> Doug Glancy wrote:
>> Andy,
>>
>> Your post reminded me that even though Intellisense doesn't show a
>> property for a control, e.g., ".top" it might still be available. I do
>> wonder though, why "top" didn't show for my earlier example of an
>> MSForms.Button, but did when I cast it as a Control? Anyways, a good
>> reminder not to rely too much on the IDE features, although generally I'd
>> be lost without them.
>>
>> Doug
>>
>> "Andy Pope" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>
>>>Hi,
>>>
>>>This works for me. Adds progress bar to userform and when the form is
>>>clicked will do a simple 1 to 100 prorgess.
>>>
>>>Private m_objPBar As Object
>>>Private Sub UserForm_Click()
>>>
>>> Dim lngIndex As Long
>>> Dim lngLoop As Long
>>>
>>> m_objPBar.Value = 0
>>> For lngIndex = 1 To 100
>>> For lngLoop = 1 To 599999
>>> Next
>>> m_objPBar.Value = m_objPBar.Value + 1
>>> Next
>>>
>>>End Sub
>>>Private Sub UserForm_Initialize()
>>>
>>> Set m_objPBar = _
>>>Me.Controls.Add("MSComctlLib.ProgCtrl.2", "myProg", True)
>>>
>>> With m_objPBar
>>> .Top = 5
>>> .Left = 5
>>> .Width = Me.InsideWidth - 10
>>> .Height = 15
>>> .Value = 0
>>> End With
>>>
>>>End Sub
>>>
>>>Cheers
>>>Andy
>>>
>>>What-A-Tool wrote:
>>>
>>>>"Bob Phillips" <(E-Mail Removed)> wrote in message
>>>>news:(E-Mail Removed)...
>>>>
>>>>
>>>>>If you want a progress bar, as you note there is no built-in control
>>>>>(there may be commercial controls, but I know of none), but you could
>>>>>just add the usual type of progress indicator as described here
>>>>>http://www.enhanceddatasystems.com/E...rogressBar.htm
>>>>>
>>>>>--
>>>>>---
>>>>>HTH
>>>>>
>>>>>Bob
>>>>>
>>>>
>>>>
>>>>So you are saying there is no way to programatically add the Microsoft
>>>>ProgressBar Control, Version 5.0 or Version 6.0, that I have available
>>>>in the "Addtional Controls" dialog box accesible from the tools menu?
>>>>These controls are contained in comctl32.ocx, or MSCOMCTL.OCX,
>>>>respectively. Is there a way to programatically create a reference to 1
>>>>of these .ocx files, and add the control from there?
>>>>
>>>>Thanks Bob -
>>>> Sean

>>
>>


 
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
Help neededin adding an additional "Warning Flag" to my current lo Danny Boy Microsoft Excel Worksheet Functions 1 10th Jun 2009 02:50 PM
Programatically adding macro to Excel - "ThisWorkbook" Aerojade Microsoft Excel Misc 3 1st Oct 2008 12:53 PM
Want to "open these additional mailboxes" programatically Midwest Muskie Microsoft Outlook VBA Programming 1 14th May 2008 05:45 PM
Adding additional "ITEMS" to Journal options Steve Blair Microsoft Outlook 2 25th Jan 2006 02:36 PM
Adding additional "ITEMS" to Journal options Steve Blair Microsoft Outlook BCM 1 25th Jan 2006 02:51 AM


Features
 

Advertising
 

Newsgroups
 


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