Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Posts
    42

    Unanswered: rename a control

    Can i rename a control on the fly ? For example, if Me!Office = 6 Then Me.Branch9 = Me!Branch. Both branch9 and branch are fields in the table products

  2. #2
    Join Date
    Oct 2002
    Location
    Baghdad, Iraq
    Posts
    697
    Quote Originally Posted by peljo
    Can i rename a control on the fly ? For example, if Me!Office = 6 Then Me.Branch9 = Me!Branch. Both branch9 and branch are fields in the table products
    I'm not sure exactly what you're asking for here. At one extreme, you can create a form from scratch and even write event handlers for the controls, all dynamically, in Access. (Note that writing event handlers kills any digital signature you added to your code, so users will get the macro virus warning.)

    Do you mean changing the caption of a control? That's easy: just Me!Foo.Caption = "whatever". That link is for label controls, the same syntax works for any controls with a caption like buttons.

    Do you mean changing the name property? No, it's read-only. You would have to delete the control and create a new one with a different name, which is tricky.

    If you want to refer to different controls depending on some variable, exactly how you do it is up to you, but you can store a reference to a control in an object variable. For example:

    Code:
    Public hotControl as Control
    ...
    
    Sub setHotControl(ByRef newHotControl as Control)
        ' **MUST** use the Set command to assign object references in VBA.
        Set hotControl = newHotControl
        ...
    End Sub
    
    Sub useHotControl()
        ...
        hotControl.Visible = True
        If VarType(hotControl) = "ComboBox" Then
            Dim hotCombo as ComboBox
            Set hotCombo = hotControl
            ' Do stuff that only a ComboBox can do
        End If
    End Sub

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I'd agree with sco08y, but before hazarding a approach I'd like to know more about what you are trying to achieve. What design goal are you trying to get renaming the controls on the fly?

Posting Permissions

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