Pass an Access Text Box Value to a VBA Import Procedure
Question details
The user wants to pass a file path from an unbound Access text box 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.
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.
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.
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.
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
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
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.

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.

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.




