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 ErrorHandlerDim fd As Office.FileDialog
Dim txt As Access.TextBox
Dim strPath As String
Dim strFilter As StringCreate 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 Withtxt.Value = strTextFileSave 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 = strTextFileErrorHandlerExit:
Exit SubPart II Writing VBA Code to Exchange Data between Office Components