Set caption of Forms in MS Access VBA
This article is about to create the routine, that will make sure all my forms have a proper title as the caption. Sometimes while creating Forms and reports, we forget to set the caption name for them. In this article we are check all the Forms from the Form collection, that has no caption name.
To implement this firstly we have to create forms for testing purpose with no caption name. Create another form contain a button for start the routine as shown in Fig 1.1. On the button event procedure, a function call, that will check the all the forms from the containers.
After write VBA code, we have click on the button, now the routine will work and open the MS Access Form that has no caption name as shown in Fig 1.2.
After check all the forms, it will show message of completion as shown in Fig 1.3.
Option Compare Database
Private Sub Command0_Click()
Public Function chkMissingCaptionForm()
Dim objDoc As DAO.Document
Dim objdbs As DAO.Database
Dim strCaptionName As String
Set objdbs = CurrentDb
For Each objDoc In objdbs.Containers("Forms").Documents
DoCmd.OpenForm objDoc.Name, acDesign
If Forms(objDoc.Name).Caption = "" Then
strCaptionName = InputBox(objDoc.Name & " has no caption. Set Caption", "Caption")
Forms(objDoc.Name).Caption = strCaptionName
DoCmd.Close acForm, objDoc.Name, acSaveYes
MsgBox "Check Complete", vbInformation
It is advised that the information provided in the article should not be used for any kind formal or production programming purposes as content of the article may not be complete or well tested. Access Guru will not be responsible for any kind of damage (monetary, time, personal or any other type) which may take place because of the usage of the content in the article.