Results 1 to 13 of 13
  1. #1
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Unanswered: Change default Object name

    When you create an object on your Form for example a line you get its name as line1, then when you create another line you get line2 and so on.. How can you change this default value. I heared about the registery. Does anyone know.
    Thanks

  2. #2
    Join Date
    Mar 2004
    Location
    belgium
    Posts
    290
    easy as it is, change the property 'name' under the 'other'_tab of the properties popup

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Thank you 4 your reply, what I meant when you create an Object it should take any other name I can determine, rather than the default name.
    Suppose I created 40 Rectangle Objects , the name property of each one will be Rectangle1, Rectangle2, ...... ,Rectangle40
    So with your mothed I have to go through them all 40 times and change their names to be r1 for example, which is not practical solution.
    I need when you create that object, it gets the name of r1, r2, ...., r40

  4. #4
    Join Date
    Mar 2004
    Location
    belgium
    Posts
    290
    yes your right about that, I encountered that problem too. Well as far as I know it is not possible. I thaught a for next loop sub could do the job, but you can only change the name in designview, but on the other hand let me know if you find any solution, so will i :-)
    Last edited by emiel; 10-21-04 at 07:43.

  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    I think it could be done through the registry, I have read sometime but don not remember now.
    Good luck too

  6. #6
    Join Date
    Sep 2004
    Posts
    161
    Only by code...

  7. #7
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Have you done it before? I mean could you change the Name of many objects and not noly during run time?

    You can use the CreateObject statement to do that throug code, but there is an easier way through the registry.

    For example: In the english Acce$$ when you create a new lable you get lable1, lable2,.... while in the german Acce$$ you get Bezeichnungsfeld1, Bezeichnungsfeld2,.....

    And these default values are stored somewhere in the registry....
    Good Luck

  8. #8
    Join Date
    Sep 2004
    Location
    Reston, VA
    Posts
    86
    Hammbakka -

    I would not mess with the Registry unless it was absolutely necessary... You can always change the control names by looping through the controls on the form in VBA code. Put this code in a separate module and change form to your form name. It loops through the controls in the same order as the tab order, I think. What I put here changes a control with a name of "Line1" to "L1". It also has extra code commented out that to where you can change it depending on the control type or for it to prompt you for a new name. Note that a label for a textbox or listbox is also considered a control and will be part of the loop.

    Code:
    Public Sub Change_ControlNames()
        Dim ctl As Control
        Dim intNoOfControls As Integer
        Dim x As Integer
        Dim strControlName As String
        
        For Each ctl In Forms("form").Controls
            intNoOfControls = intNoOfControls + 1
        Next ctl
        
        For x = 0 To intNoOfControls - 1
        
            strControlName = Forms("form").Controls(x).Name
            
            'Example: This code will change List1 to L1
            Forms("form").Controls(x).Name = VBA.Left$(strControlName, 1) & _
                VBA.Right$(strControlName, 1)
            
            'Or, change only certain types of controls
            'Set ctl = Forms("form").Controls(x)
            'Select Case ctl.ControlType
                'Case acTextBox
                    'Do something here
                'Case acListBox
                    'Do something here
                'etc...
            'End Select
    
            'Or, prompt the user for a new name each time
            'Forms("form").Controls(x).Name = _
                VBA.InputBox("Enter a new name for " & strControlName,,"Enter")
                
        Next
        
        Set ctl = Nothing
        
    End Sub
    Last edited by BummerJeff; 10-21-04 at 10:18.

  9. #9
    Join Date
    Sep 2004
    Posts
    161
    I have serching in the registry but nada

  10. #10
    Join Date
    Mar 2004
    Location
    belgium
    Posts
    290
    Would be nice if it works, but you get runtime error 2136 and the msg "To set this property, open the form or report in designview". However when I tried it out some controls did change of name ???? strange.
    However if you have 40 changes to make remember that you will encounter double names if

    VBA.Right$(strControlName, 1)

    picks only the last character, so after ten times you have to change to

    VBA.Right$(strControlName, 2)

    or better replace this with

    trim(str(x))

  11. #11
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Quote Originally Posted by BummerJeff
    Hammbakka -

    I would not mess with the Registry unless it was absolutely necessary... You can always change the control names by looping through the controls on the form in VBA code. Put this code in a separate module and change form to your form name. It loops through the controls in the same order as the tab order, I think. What I put here changes a control with a name of "Line1" to "L1". It also has extra code commented out that to where you can change it depending on the control type or for it to prompt you for a new name. Note that a label for a textbox or listbox is also considered a control and will be part of the loop.
    When it works, it changes it only during the run time, what I need, is changing the control name for always

  12. #12
    Join Date
    Sep 2004
    Posts
    161
    Yes your form must be open, in designview and you must save the change

  13. #13
    Join Date
    Sep 2004
    Location
    Reston, VA
    Posts
    86
    Quote Originally Posted by hammbakka
    When it works, it changes it only during the run time, what I need, is changing the control name for always
    Don't know if you can do this...looked in the Registry and couldn't find where the default names are stored. I'm guessing they are determined by the Access Wizards (acwzlib.mde, acwzmain.mde, acwztool.mde), which you can't edit anyway. The only way I see to get around this would be to create a new toolbar with buttons that will place controls on your form (just like the Controls Toolbox) but have code behind each button to set your own custom default name off of what Access assigns.

Posting Permissions

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