Access

Cambiar el nombre de las etiquetas asociadas en el formulario de Access activo

VBA

Módulo estándar

Esté en la vista Diseño o Disposición del formulario en el que desea cambiar el nombre de las etiquetas y luego ejecute ActiveForm_RenameAssociatedLabels_s4p

Si no le gusta lo que hizo, no guarde el formulario. Busque en la ventana de depuración los detalles para ver los nombres de los controles de etiquetas antiguos y nuevos.

Option Compare Database 
Option Explicit 

'*************** Code Start *****************************************************
' module name: mod_ActiveForm_RenameAssociatedLabels_s4p
'-------------------------------------------------------------------------------
' Purpose  : rename associated label controls to "controlname_Label"
'                 FORM MUST BE IN DESIGN or LAYOUT VIEW AND ACTIVE
' Author   : crystal (strive4peace)
' web site : 
' This code: /tool/ActiveForm_RenameAssociatedLabels.htm
' LICENSE  :
'   You may freely use and share this code, but not sell it.
'   Keep attribution. Mark your changes. Use at your own risk
'-------------------------------------------------------------------------------
'           ActiveForm_RenameAssociatedLabels_s4p
'-------------------------------------------------------------------------------
Public Sub ActiveForm_RenameAssociatedLabels_s4p() 
'150225, strive4peace, 231003, 05

   'Click HERE and press F5 to Run!
   
   'CALLs
   '  GetControlname_Label_s4p
   
   On Error GoTo Proc_Err 

   Dim oControl As Control _ 
      ,obj As Object 
      
   Dim sControlName As String _ 
      ,sLabelName As String _ 
      ,sLabelNameNew As String _ 
      ,sMsg As String _ 
      ,iCount As Integer 
   
   iCount = 0 
   
   Set obj = Screen.ActiveForm 
   
   With obj 
      If MsgBox(.Name _ 
            & vbCrLf & vbCrLf &  "Rename labels? " _ 
            ,vbYesNo, "Rename Controls on " & .Name &  "?") _ 
      = vbNo Then Exit Sub 
      
      Debug.Print  "*** rename label controls on " & .Name 
      
      For Each oControl In .Controls 
         If oControl.ControlType  acLabel Then 
            sControlName = oControl.Name 
            
            sLabelName = GetControlname_Label_s4p(oControl) 
            
            If sLabelName   "" Then 
               'change this if you want to name labels differently
               sLabelNameNew = sControlName &  "_Label"
               If sLabelName  sLabelNameNew Then 
                  Debug.Print Space(3) & sLabelName _ 
                              &  " --> " & sLabelNameNew 
                  .Controls(sLabelName).Name = sLabelNameNew 
                  iCount = iCount + 1 
               End If 
            End If 
         End If 
      Next oControl 
   End With   'obj ActiveForm
   
   sMsg =  "Renamed " & iCount &  " label controls"
   Debug.Print sMsg 
 
   sMsg = sMsg & vbCrLf & vbCrLf &  "Look at Debug window for details"
   MsgBox sMsg,, "Done"
      
Proc_Exit: 
   On Error Resume Next 
   Set oControl = Nothing 
   Set obj = Nothing 
   On Error GoTo 0 
   Exit Sub 
  
Proc_Err: 
   'err 2104 'name already in use
   '     -- fix this manually or modify this code
   MsgBox Err.Description _ 
        ,, "ERROR " & Err.Number _ 
        &  "   RenameAssociatedLabel_Controls"

   Resume Proc_Exit 
   Resume 
End Sub 
'-------------------------------------------------------------------------------
'           GetControlname_Label_s4p
'-------------------------------------------------------------------------------
Private Function GetControlname_Label_s4p( _ 
   poControl As Control _ 
   ) As String 
'220425 strive4peace,231003
   On Error GoTo Proc_Err 
   Dim sControlSource As String 
   GetControlname_Label_s4p =  ""
   
   With poControl.Controls(0) 
      If .ControlType  acLabel Then Exit Function 
      GetControlname_Label_s4p = .Name 
   End With 
   
Proc_Exit: 
   On Error GoTo 0 
   Exit Function 
  
Proc_Err: 
   Resume Proc_Exit 
   Resume 
   
End Function 
'*************** Code End *****************************************************

‘ El código se generó con colores utilizando el complemento gratuito Color Code para Access

Publicaciones relacionadas

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Botón volver arriba