Solved

Creating objects on a form using Form_Load.....

Posted on 2001-06-20
9
158 Views
Last Modified: 2010-05-02
Ok, this one is a bit harder.

I want 31 new labels for my form, with the values 1 - 31. I know there must be an easier way to add them other then manually enter them in, so I thought I would ask the experts!!

I appreciate any help

Lewis Keen
a.k.a Yeggstry
0
Comment
Question by:yeggstry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 6

Expert Comment

by:JonFish85
ID: 6211913
Dim lbl As Label
Dim cnt As Integer

LastTop = 0
For cnt = 1 to 31
  Set lbl = Me.Controls.Add("VB.Label", "lbl" & cnt)
  With lbl
    .Move 10, cnt
    .AutoSize = True
    .Visible = True
    .Caption = cnt
  End With
Next cnt


try that maybe?
0
 

Author Comment

by:yeggstry
ID: 6211923
cheers, i will try, but any other solutions are welcome!!
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6211933
also you can add one label to your form, name it lblNumbers and set its index property to 0. then:

Dim cnt as Integer

for cnt = 1 to 31
  Load lblNumbers(lblNumbers.UBound + 1)
  With lblNumbers(lblNumbers.UBound)
    .Top = lblNumbers(lblNumbers.UBound - 1).Top + .Height
    .Left = 10
    .Caption = cnt
    .Visible = True
  End With
Next cnt
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 15

Accepted Solution

by:
ameba earned 200 total points
ID: 6212637
To add labels at design time, use some add-in or create your own.
Simple sample:
Start new Add-In project (menu File, New Project, AddIn) - this will create Connect.Dsr and frmAddIn form.
Replace code in frmAddIn with this:

' frmaddIn, add one textbox (2 buttons are already on form)
Option Explicit
Public VBInstance As VBIDE.VBE
Public Connect As Connect

Private Sub CancelButton_Click()
    Connect.Hide
End Sub

Private Sub Form_Load()
    Caption = "Enter number of labels on new form"
    Text1.Text = "31"
End Sub

Private Sub OKButton_Click()
    Dim myC As VBControl, thisF As VBForm, i As Integer
    On Error Resume Next
   
    ' add new form
    Set thisF = VBInstance.VBProjects(1).VBComponents.Add(vbext_ct_VBForm).Designer
    For i = 1 To CInt(Text1.Text)
        Set myC = thisF.ContainedVBControls.Add("VB.Label")
        myC.Properties("Visible") = True
        myC.Properties("left") = 300
        myC.Properties("top") = i * 225
        myC.Properties("name") = "Label" & CStr(i)
        myC.Properties("height") = 225
        myC.Properties("width") = 2775
        myC.ControlObject.Caption = CStr(i)
    Next
End Sub
' -------------------------------------
To test addin, press F5, start new instance of VB, and click menu Add-Ins, My Addin.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6213138
ameba,
thats interesting.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6453660
Why did you punish me with a B ???

If something wasn't clear, you should have asked for clarification or for more info.

Do NOT expect any further help from me!
0
 

Author Comment

by:yeggstry
ID: 6453672
grow up ameba

I gave you a B because your answer was sufficient, but could have been better.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6454272
>grow up ameba

Some people really don't deserve ANY HELP!
0
 

Expert Comment

by:amp072397
ID: 6711598
Well, I've found my way to this question rather indirectly. However, B grades are not given if the answer was sufficient. Yeggstry, I'll gladly post the guidelines for grading. If you did not know the answer, how could you possibly know that the answer could have been better?

Changing grade to an A...

amp
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question