Access – VBA – Make Form Labels Proper Case

Trying to help out in a forum where the user was looking for an automated way to make all the labels, within a form, Proper Case.

Below was the solution

'---------------------------------------------------------------------------------------
' Procedure : Form_ProperCaseLabels
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Open the specified form and update all the form labels to Proper Case
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
'             (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: None required
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sFormName : Name of the form to process
'
' Usage:
' ~~~~~~
' Call Form_ProperCaseLabels("YourFormName")
' Form_ProperCaseLabels "Form1"
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2019-09-04              Initial Release, Forum Help
'---------------------------------------------------------------------------------------
Sub Form_ProperCaseLabels(ByVal sFormName As String)
    Dim frm                   As Access.Form
    Dim ctrl                  As Access.Control

    On Error GoTo Error_Handler

    DoCmd.OpenForm sFormName, acDesign
    Set frm = Forms(sFormName)
    For Each ctrl In frm.Controls
        If ctrl.ControlType = acLabel Then
            ctrl.Caption = StrConv(ctrl.Caption, vbProperCase)
        End If
    Next ctrl
    DoCmd.Close acForm, sFormName, acSaveYes

Error_Handler_Exit:
    On Error Resume Next
    If Not ctrl Is Nothing Then Set ctrl = Nothing
    If Not frm Is Nothing Then Set frm = Nothing
    Exit Sub

Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: Form_ProperCaseLabels" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Sub

What About Reports?!

Similarly, with a few minor changes, you can do the same thing for reports, as shown below:

'---------------------------------------------------------------------------------------
' Procedure : Report_ProperCaseLabels
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Open the specified report and update all the report labels to Proper Case
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
'             (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: None required
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sReportName : Name of the report to process
'
' Usage:
' ~~~~~~
' Call Report_ProperCaseLabels("YourReportName")
' Report_ProperCaseLabels "Report1"
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2019-09-04              Initial Release
'---------------------------------------------------------------------------------------
Sub Report_ProperCaseLabels(ByVal sReportName As String)
    Dim rpt                   As Access.Report
    Dim ctrl                  As Access.Control

    On Error GoTo Error_Handler

    DoCmd.OpenReport sReportName, acDesign
    Set rpt = Reports(sReportName)
    For Each ctrl In rpt.Controls
        If ctrl.ControlType = acLabel Then
            ctrl.Caption = StrConv(ctrl.Caption, vbProperCase)
        End If
    Next ctrl
    DoCmd.Close acReport, sReportName, acSaveYes

Error_Handler_Exit:
    On Error Resume Next
    If Not ctrl Is Nothing Then Set ctrl = Nothing
    If Not rpt Is Nothing Then Set rpt = Nothing
    Exit Sub

Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: Report_ProperCaseLabels" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Sub

I thought it might be able to serve others.

3 responses on “Access – VBA – Make Form Labels Proper Case

    1. Daniel Pineault Post author

      Sorry about that Peter. It took me longer than I thought it would, but I finally updated all the entries in my website to fix this issue. Thank you for pointing it out!

  1. Pam

    Hi Daniel,
    Just wanted to say ‘Thank You’ – again!! The code you provided for proper case labels on a form when I asked in the forum saved me a tremendous amount of time. Now, I see where you have included code for reports, as well. I have used it for the report and again, it was a time saver.
    Your time, help and postings are greatly appreciated!!