The “Source Text File” command button’s event procedure opens a File Picker dialog for selecting a
text file for importing, filtering for either text or comma-delimited files depending on the option
selected on the form:
Private Sub cmdSourceTextFile_Click()
On Error GoTo ErrorHandler
Dim fd As Office.FileDialog
Dim txt As Access.TextBox
Dim strPath As String
Dim strFilter As String
Create a FileDialogobject as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Set txt = Me![txtSelectedTextFile]
Set the initial path to the custom Input Documents path.
strPath = GetInputDocsPath()
intTextType = Nz(Me![fraTextType].Value, 1)
With fd
.title = “Select text file with job data to import”
.ButtonName = “Select”
.Filters.Clear
If intTextType = 1 Then
.Filters.Add “Comma-delimited files”, “*.csv”
ElseIf intTextType = 2 Then
.Filters.Add “Fixed-width files”, “*.txt”
End If
.InitialView = msoFileDialogViewDetails
.InitialFileName = strPath
If .Show = -1 Then
strTextFile = CStr(fd.SelectedItems.Item(1))
Else
Debug.Print “User pressed Cancel”
End If
End With
txt.Value = strTextFile
Save the value to tblInfo; the form can’t be bound to that table because the main menu is bound to
it, and thus it is locked.
SaveTextFile (strTextFile)
Me![txtSelectedTextFile].Value = strTextFile
ErrorHandlerExit:
Exit Sub
Part II Writing VBA Code to Exchange Data between Office Components