Others

Update a Label Caption in Another Microsoft Access Database with VBA

Nimra MalikNimra Malik Nov 20, 2026 869 views

Question details

The user needs to display the current update date on a label in a secondary Access database.

Update a Label Caption in Another Microsoft Access Database with VBA
Product
Microsoft Access
Device & OS
not provided
Scenario
A primary database opens and updates other databases one at a time, and each secondary database has a startup form.
Observed behavior
The VBA code changes a label in the primary database, and a reference to the secondary database's form produces a compile error.
Before you start

Identify the full path of each secondary database and confirm that you can write to it. Make sure each database has a startup form where you can add a label and an On Open event procedure.

Solution 1Recommended

Store the Update Date in Each Database and Display It on the Startup Form

Use a one-record table when the date must remain available after the form closes and reopen with the database.

In a form module, Me refers to the form running the code, not a form in another database. Store the date in the secondary database instead, then let its own startup form read the value.

The example assumes that each secondary database contains a table named UpdateInfo with a numeric ID field and a Date/Time field named LastUpdated.

1
Create the date record

In each secondary database, use Create > Table Design to create UpdateInfo with ID as a numeric primary key and LastUpdated as a Date/Time field. Open the table in Datasheet View and add a record with ID set to 1.

2
Update the secondary table

In the primary database's VBA editor, run the following code after completing the update. Replace the path with the secondary database's actual path: Dim dbPath As String dbPath = "C:\Data\Secondary.accdb" CurrentDb.Execute "UPDATE [UpdateInfo] IN '" & Replace(dbPath, "'", "''") & "' SET [LastUpdated] = Date() WHERE [ID] = 1;", dbFailOnError

3
Read the date on form open

Open the secondary database's startup form in Design View and name the label lblUpdated. In the form's Property Sheet, set On Open to Event Procedure, click the build button, and add this code inside Form_Open: Dim updateDate As Variant updateDate = DLookup("[LastUpdated]", "[UpdateInfo]", "[ID] = 1") If IsNull(updateDate) Then Me.lblUpdated.Caption = "Update date not available" Else Me.lblUpdated.Caption = "Last updated: " & Format$(updateDate, "mmm d, yyyy") End If

4
Test the result

Save the form, run the update code from the primary database, and reopen the secondary database. Its startup form should show the stored date on lblUpdated.

Store the Update Date in Each Database and Display It on the Startup Form
Form already open: The On Open event runs when the form opens. If the form is already open when the table is updated, close and reopen it or run equivalent label-refresh code in that database.
Free Microsoft Office alternative

Use WPS Office for Everyday Office Documents

WPS Office is a free, lightweight alternative with a familiar interface for working with compatible Microsoft Office documents. It can help you move everyday document work to WPS, but it does not fix Access VBA or replace an Access database.

Use a familiar interface for documents, spreadsheets, and presentationsOpen and edit Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXKeep related spreadsheets and reports accessible alongside your Access workflowGet started with a free, lightweight Office alternative
microsoft office alternative - wps office

Frequently Asked Questions

Why does Me refer to the label in the wrong database?

Me refers to the form instance whose module is running the VBA code. It does not identify a form in a separate Access database.

Will a caption changed in Form view remain after the form closes?

A runtime caption change generally does not persist as a saved form design change. Store the date in a table and set the caption again in the form's On Open event.

What if the startup form is already open when the date is updated?

The On Open event will not run again automatically. Close and reopen the form, or add code in the secondary database that rereads the table and refreshes the label.

Why does the UPDATE query not change a date?

Check the database path, write permissions, table and field names, and confirm that UpdateInfo contains a record with ID 1. The UPDATE query does not create a missing record.