Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Add Label at run-time on a Multipage


Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2009, 10:01 AM
pale_rider pale_rider is offline
Newcomer
 
Join Date: Mar 2009
Posts: 10
Default Add Label at run-time on a Multipage


I'm trying to add a label at runtime and place it on a MultiPage Control on a user form. Here is my code:

Code:
TopPos = 156

Dim myLabel As MSForms.Label
Set myLabel = AnalyzeForm.Controls.Add("Forms.Label.1")
With myLabel
.Name = "ID" & item
.Height = 14
.Left = 12
.Top = TopPos
.Width = 24
.Caption = IDCaption
.BorderStyle = fmBorderStyleSingle
.Font.Bold = True
.Font.Size = 10
End With
I'm having trouble with the syntax on the bold line. As I have it coded, it adds it to the right userform, but it's not on the multipage control. I need to learn how to place it on the correct page of the multipage control: MultiPage1.... Page 2. Thanks.
Reply With Quote
  #2  
Old 03-31-2009, 03:26 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline
Out Of Office

Retired Moderator
* Expert *
 
Join Date: Mar 2005
Location: London, UK
Posts: 3,398
Default

The Page object has a controls property which you can use to add the control. This is not shown by intellisense if you use an index of the multipage control's pages collection, so you may find it more transparent if you use a Page object variable.

Code:
    Dim myLabel As msforms.Label
    Dim pge As msforms.Page
    
    'let's get a reference to the last page on the multipage control
    'remember the index starts at 0, not 1
    With MultiPage1
        Set pge = .Pages(.Pages.Count - 1)
    End With
    
    Set myLabel = pge.Controls.Add("Forms.Label.1")
    
    With myLabel
        .Caption = "This is a new label"
        .Visible = True
        .Top = MultiPage1.Top + 5
        .Left = MultiPage1.Left + 5
    End With
If you type in the line in red manually, you will see intellisense kicking in and offering you the controls property.


Alternatively, you could add the label and make it hidden at design time, and then just make it visible at runtime if it is needed.

Hope that helps...
Colin
__________________
RAD Excel Blog
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->