Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    3

    Unanswered: Change the name of a control using VBA?

    Can anyone tell me how to change the name of a control on a form using VBA please.
    I know I can use properties such as:

    me.controlName.caption = "CaptionName"

    but I can't use the '.name' property to change the name whilst the form is not in design mode. I have tried to do it from another form but I don't know how to reference it as I keep getting an error message.

    Can anyone help please.

    Thanks
    Red

  2. #2
    Join Date
    Jun 2004
    Location
    Terrapin Nation
    Posts
    205
    Why would you want to do that? You can always use the tag property to store any text in you would want. You could store a 'virtual' name in that property.

  3. #3
    Join Date
    Aug 2004
    Posts
    3
    I want to create some controls dynamically and have them sequentially named (i.e. control1, control2,...) becasue I am going to use the text & caption properties for each control in an variable array.

    i.e. me(control + format$ (Intx)).text = "whatever"

    The number of controls needed will vary depending on a user input in another form. I intend to open up the target form in design mode, add the controls (which is why they have to be named as such.) and then populate the text & caption properties depending on a previuos user selection.

    As far as my problem is concerned I have got around it by adding a maximum number of controls and hiding what I don't need. It just would have been good to know how to add & name them through code.

    Cheers anyway.
    Red

  4. #4
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    You can only do it in design mode and that limits you to one user at a time. The reason is Access only allows one person to edit forms, modules, etc. at one time in versions 2000 and later.

    If you don't plan on having more than one user (for example each user has their own front end) then you could probably get away with it. Me personally I would add all of the controls to the form and hide the ones I don't need. How many controls are you dealing with?

Posting Permissions

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