VBA & Macro Problems

Pass an Access Text Box Value to a VBA Import Procedure

Amos GikundaAmos Gikunda Nov 18, 2026 868 views

Question details

The user wants to pass a file path from an unbound Access text box to a VBA import procedure.

Pass an Access Text Box Value to a VBA Import Procedure
Product
Microsoft Access
Device & OS
not provided
Scenario
A user selects a file path on an Access form and wants an import routine in a standard module to use it.
Observed behavior
The import procedure needs to receive and validate the selected path before using it.
Before you start

Confirm the names of the form, unbound text box, and import button in Access. The example below uses txtFilePath and cmdImport; replace them with your control names.

Solution 1Recommended

Pass the Text Box Value as a VBA Procedure Argument

Use an explicit argument to send the selected path from the form to an import procedure in a standard module.

The text box can remain unbound. Passing its value as an argument keeps the standard module independent of the form name.

1
Open the button event

Open the form in Design View, select the import button, and use its Property Sheet to set On Click to [Event Procedure]. Click the builder button to open the VBA editor.

2
Pass the selected path

In the button's Click event, read the text box and call the procedure. For example: Private Sub cmdImport_Click() Dim filePath As String filePath = Trim$(Nz(Me!txtFilePath.Value, "")) ImportFile filePath End Sub

3
Add the module procedure

In the VBA editor, choose Insert > Module and add a public procedure that validates the path before your import code: Public Sub ImportFile(ByVal filePath As String) If Len(filePath) = 0 Then MsgBox "Select a file first." Exit Sub End If If Len(Dir$(filePath)) = 0 Then MsgBox "The selected file was not found." Exit Sub End If ' Add your file-specific import code here. End Sub

4
Test the import

Save the form and module, open the form in Form View, select a file so its path appears in txtFilePath, and click the import button. Test an empty or unavailable path as well.

Pass the Text Box Value as a VBA Procedure Argument
Add the appropriate import command: The example validates the path but does not import a file. Add the import command for your file type and destination where indicated.
Free Microsoft Office alternative

Work With Office Files in WPS Office

WPS Office is a free, lightweight alternative for working with documents and spreadsheets in a familiar interface. Its Microsoft Office format compatibility helps with migration, but it does not replace an Access database or run this Access VBA import procedure.

Review spreadsheet data in WPS Spreadsheets before using it in an import workflowOpen and edit common Microsoft Office formats, including XLSX and DOCXUse familiar document and spreadsheet toolsGet started with a free, lightweight office suite
QA img-9

Frequently Asked Questions

Does the Access text box need to be bound to a table?

No. An unbound text box can hold the selected path. Read it in the form's button Click event with Me!txtFilePath.Value and pass the value to your procedure.

Why use Nz when reading the text box?

An empty Access text box may contain Null. Nz(Me!txtFilePath.Value, "") substitutes an empty string so the procedure can check it with Len.

Can a standard module read the text box directly?

Yes, while the form is open, a standard module can reference Forms!YourFormName!txtFilePath.Value. Passing the value as an argument avoids tying the module to that form name.

Does checking the path with Dir import the file?

No. Dir checks whether the specified file can be found; you still need an import command appropriate to the file type and destination.