Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2009

    Unanswered: Creating Components at Real-time


    I am trying to create a series of labels at real-time.

    Here is what I am basically trying to do.

    if not rs.eof then
    While not rs.eof
    Load lblDate(x)
    lblDate(x).visible = true

    End If


  2. #2
    Join Date
    Nov 2007
    Adelaide, South Australia
    And the problem is?

    I tend to create a mass of label controls on the form and then hide/reveal/move as appropriate rather than trying to create them on the fly.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!

    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    Creating controls on a form has absolutely nothing to do with opening a recordset, which is what the code you posted would indicate you're trying to do. A label is not attached to a particular record, although, as the Trekkie suggested, you can use conditional formatting in the Form_Current event, in a Single View form, to make a label appear or disappear depending on values in the given record.

    There is a method called CreateControl that will allow for the creation of a control, such as a label, at run-time (not real-time, BTW) but I cannot stress enough what a terrible idea this is! Trekkie's suggestion is really the only way to go with this.

    CreateControl requires opening the form in Design View, so you can't actually create them while your form is running. So what you'd be looking at would be is

    1. Open your form in whatever view
    2. Run your code
    3. Close the form
    4. Re-open it in Design View
    5. Create the labels with the code that triggered the whole thing
    6. Save the form
    7. Close the form
    8. Re-open the form in such a way that the whole process wouldn't start all over again

    My guess is that this would turn into an enormous hairball where the return on time invested would never justify doing it. Ive been programming since 1990 and I would never even consider undertaking such a project.

    Go with the Trekkie's idea. If you need help when you get into it, someone here can show you how to control the visibility of groups of labels without doing each one individually.

    Good luck!
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Feb 2009

    I have created a label called lblDate(0) at design time

    Here is the runtime code
    Private Sub Command21_Click()
    On Error GoTo Err_Command21_Click

    Load (lblDate(1))
    lblDate(1).Left = lblDate(0).Left + 200
    lblDate(1).Top = lblDate(0).Top
    lblDate(1).Caption = "Test1"
    lblDate(1).Visible = True
    Exit Sub
    MsgBox Err.Description
    Resume Exit_Command21_Click

    End Sub

    Here is the Error - "Sub or Function not defined"


  5. #5
    Join Date
    Mar 2009
    Provided Answers: 14
    This is VBA not VB. You cannot create a control array in VBA.
    see: Forms: Control Arrays in Access

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts