Wonderful,
With the form version of the checkbox, everytime you toggle the state the assigned macro will run.
To refer to the control, you will refer to the worksheet's shapes collection... The fun part is that you have things like "Check Box 1" and "Check Box 3" etc... YUCK
Wouldn't be better to refer to the control via a normal name such as "chkbx_insertintials"... well this code will step thru all of the form-control checkbox formated shapes and allow you to change the name...
KEEP IN MIND THE FOLLOWING:
Access 2007 reserved words and symbols AllenBrowne- Problem names and reserved words in Access
If you try to rename the controls using spaces or reserved charactors or reserved names, the control will not usually accept the new name.
(and for some reason it will not accept the original name either... strange)
- Option Explicit
-
-
Sub Z_List_and_or_Rename_ChkBx()
-
Dim zwrkb As Workbook
-
Dim zwrks As Worksheet
-
Dim zshapes As Shapes
-
Dim zshape As Shape
-
Dim zprmpt As String
-
Dim zstr As String
-
'
-
Set zwrkb = ActiveWorkbook
-
Set zwrks = zwrkb.ActiveSheet
-
Set zshapes = zwrks.Shapes
-
'
-
On Error GoTo zerr
-
Debug.Print ">>"
-
For Each zshape In zshapes
-
With zshape
-
If .Type = msoFormControl Then
-
If .FormControlType = xlCheckBox Then
-
Debug.Print .Name, .ID, .AlternativeText, .ControlFormat.Value
-
zprmpt = "Control with text: " & .AlternativeText & vbCrLf & _
-
"ID Number: " & .ID & vbCrLf & _
-
"Is Currently Named..."
-
zstr = InputBox( _
-
Prompt:=zprmpt, _
-
Default:=.Name, Title:="Rename?")
-
-
If zstr = "" Or zstr = .Name Then
-
.Name = .Name
-
Else
-
Debug.Print .Name & " Renamed to: ",
-
.Name = zstr
-
Debug.Print .Name
-
End If
-
'(Press <ctrl><g> to open the immediate window to see what is printing
-
End If
-
End If
-
End With
-
Next
-
'
-
Debug.Print "<<"
-
Set zshapes = Nothing
-
Set zwrks = Nothing
-
Set zwrkb = Nothing
-
-
Exit Sub
-
zerr:
-
Debug.Print Err.Description
-
Resume Next
-
End Sub
To use, simply copy and paste into the workbook into a standard module...
Select the worksheet with the controls of interest...
Enter your text next to each control...
then run the code as you would another macro
Now either keep track of the original names... you can copy and past from the immedates window into a textfile... or rename as needed. You will need to refer to control name to determine the value and therefor to toggle the intials.