Results 1 to 10 of 10
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Change the names of controls from code


    Can one make permanent name changes to text box controls in general module code versus design mode on the form itself?

    Something like:

    Code:
    dim I as integer
    dim intMate as integer
    
    For I = 122 to 131
         intMate  = I + 131
         Form("frmPrkgSouth").controls("Text" & intMate ).name = "tb" & I & "A"
    next I

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Only if you open the form in design view first. Something like
    Code:
    Sub ChangeName()
    DoCmd.OpenForm "form1", acDesign, , , , acHidden
    Forms!form1.Text0.Name = "test"
    DoCmd.Save acForm, "form1"
    DoCmd.Close acForm, "form1"
    End Sub
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks, I'll code up a module mid-day or so on Tuesday and post back the code............ when it works, of course

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Why would you need to programmatically change control names?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    This is indeed a strange one. I have a few graphic type forms like you see in the snipped screenshot. The "red row" controls are from a copy/paste of the adjacent row. The "pasted row" controls are given their control names serially. I need them named such that they become known when the OnLoad code loops through the Text Box Collection of the "copied row". I was changing each control's name manually according to their "mate" in design mode and was getting tired of the typing errors or omissions. Since I have 100's of these pesty controls to rename (thanks user), I posted here to see if I could do the renaming from some simple code. For example, slot 192 is control "tb192" its mate control name needs to be "tb192A" so that the OnLoad code knows which control to set when "tb192" appears when looping the text box collection, namely the value 439 returned from a Lookup.

    Click image for larger version. 

Name:	000.jpg 
Views:	19 
Size:	82.9 KB 
ID:	46976

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks Micron, your suggestion worked great and save me a lot of error prone manual "grunt" work. Now, I just tweak the code as necessary to accommodate the other forms with the same issue.
    Code:
    Option Compare Database
    Option Explicit
    Dim I As Integer
    Dim J As Integer
    Dim intMate As Integer
    Sub ChangeName()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  01/05/2022 - Micron's suggested solution to updating control names
    '  for the apartment text boxes.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    DoCmd.OpenForm "frmPrkgSouth", acDesign, , , , acHidden
    
    
    For I = 113 To 131
         intMate = I + 131    '(244-262)
         Forms!frmPrkgSouth.Controls("Text" & intMate).Name = "tb" & I & "A"
    Next
    
    
    For I = 150 To 166
         intMate = I + 125    '(275-291)
         Forms!frmPrkgSouth.Controls("Text" & intMate).Name = "tb" & I & "A"
    Next
    
    
    J = 268
    For I = 107 To 112
         intMate = J    '(268-263)
         J = J - 1
         Forms!frmPrkgSouth.Controls("Text" & intMate).Name = "tb" & I & "A"
    Next
    
    
    J = 274
    For I = 101 To 106
         intMate = J    '(274-269)
         J = J - 1
         Forms!frmPrkgSouth.Controls("Text" & intMate).Name = "tb" & I & "A"
    Next
    
    
    DoCmd.Save acForm, "frmPrkgSouth"
    DoCmd.Close acForm, "frmPrkgSouth"
    End Sub

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You're welcome - not that I did much. You could pass the name of the form to a procedure for the Open method part (or pass the form itself and reduce the Forms! repetition), but I imagine that the names of the controls will be different every time, so not much you can do to make this any easier?

    One thing that might come in handy when relating code to a thread is to include the thread url in the code commentary. I do that often - much easier than trying to find the forum thread via forum search function in case it's needed.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Ok, I understand the design and faced similar issue, just not so many controls that programming effort was called for. I suffered through about an hour of manually renaming controls and was done.

    If using DLookup to pull values for hundreds of controls, is the form loading fast enough?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    The forms involved and the "TEXTxxx" names generated by Access during the paste required manual observation in design mode to get the "loop bounds", so a more generalized approach simply wasn't possible. A whole lot less work than doing the renames manually.............YUCK!

    include the thread url in the code commentary
    Great idea, especially with a somewhat strange one like this caper.
    Thanks again,
    Bill

  10. #10
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    After about an hour of manual renaming, I could see what remained and decided I'd had enough.

    is the form loading fast enough?
    Yes.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 03-21-2018, 04:58 AM
  2. Replies: 0
    Last Post: 11-24-2015, 07:41 PM
  3. Replies: 3
    Last Post: 11-05-2014, 11:46 AM
  4. Dealing with controls with spaces in their names
    By zippy483 in forum Programming
    Replies: 4
    Last Post: 02-28-2013, 04:20 AM
  5. Change controls on an empty form
    By Dom in forum Forms
    Replies: 2
    Last Post: 01-19-2011, 08:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums