Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    91

    Unanswered: Create New Label

    How to create new Access.Label from VB code?

  2. #2
    Join Date
    Sep 2002
    Location
    Coventry, Warwickshire, UK
    Posts
    74
    I assume that you want to change the label that describes a text control, for example.

    If you select the the control title and open the properties, you will see the wording for the title is held in the Caption property. Therefore, you can replace it by using the code

    Me!Label1.Caption = "New Text"

    where Me refers to the current form in which this line of code appears
    and Label1 is the name of the control.

    Me only works if the code is in the code behind the form. If it is in a module, you reference the form as follows

    Forms!Form_Name!Label1.Caption = "New Text"
    Roger Hampson
    XI - ecs (UK) Ltd

  3. #3
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    91

    I want the new...

    No..., I want the new object...

    By the way, I already try the method of creating dummy transparent label... with name Label0, Label1, ... (as this is the access default)
    And use and modify its property using Me.Controls("Label" & index) from the code according to the number of label that is required. Using this method, I will be limited to only the label that are already on the form. I can't create new label.

    Furthermore, I can't create new object beside label, as this will break the access default numbering. When I have 100 label for example, when I draw the line, or other control, the number will be 101... and I can't get Label101 automatically... Renaming the label will be quite troublesome...

  4. #4
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Create New Label

    Anyone got the answer to this one?

    I need to do this also.

    (to create new labels via vba in a report)

    GD

  5. #5
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Red face Can It be done?

    I've found another solution to my problem, although out of interest, can you create a control on a report?

    The createreportcontrol method seems that it can only work in design view... i.e. For a Label

    Dim lblnew As Control
    Set lblnew = CreateReportControl(Report__rptTestReport.Name, acLabel)

    Gives the error "you must be in design view to create or delete controls

    ref:
    http://msdn.microsoft.com/library/de...ateControl.asp

    Just out of curiosity IS there a way of creating a control "on the fly"???

  6. #6
    Join Date
    Sep 2002
    Location
    Coventry, Warwickshire, UK
    Posts
    74
    There is also a CreateControl method which allows controls to be created on a form - but again only when in Design view.

    Perhaps you could open the form .visible=False in Design view, add your control, switch it to Normal view and then make it visible.
    Roger Hampson
    XI - ecs (UK) Ltd

  7. #7
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Wink Nice Idea

    Ill give it a try - Think we're on the right lines here

  8. #8
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Unsure where to put code???

    There is a command button on the form which opens the report

    In the click event, I have included this code;

    ....etc...

    stDocName = "rptPlannerEDB"
    DoCmd.OpenReport stDocName, acViewDesign

    With Report_rptPlannerEDB
    .Visible = False
    End With

    Dim lbltest As Label
    Set lbltest = CreateReportControl(Report_rptPlannerEDB.Name, acLabel, acHeader, "", "", 567, 567, 567, 567)

    With lbltest
    .Caption = "testing"
    End With

    With Report_rptPlannerEDB
    .Visible = True
    End With

    I am getting one of two errors;

    Either out of memory???

    Or microsoft access can't create, rename, or delete the control(s)

    Have I put the code in the right place???

    Has anyone successfully created labels on the fly...

    ...In my particular case, the report is like a "Month Planner" / Diary which I want to change the header day names depending on what month is selected from the underlying form...

    The labels for the days ie 1st 2nd 3rd all exist and I just calculate which ones should be made "invisible" if a month does not include them

    Out our interest, I would like to create the labels for each day name
    dynamically, although I have a work round in the current situation...

  9. #9
    Join Date
    Sep 2002
    Location
    Coventry, Warwickshire, UK
    Posts
    74
    Try DIMming lblTest as Control rather than Label

    Also have a look at the help text for CreateControl.
    Roger Hampson
    XI - ecs (UK) Ltd

Posting Permissions

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