K
Kate
I want to create a form to export data from a query and save it in a .csv
file. I can figure out how to use the msoFileDialogFilePicker code to select
a file that already exists and write the new data into it. But how do I
allow the user to input a new file name and have the data write out to that.
Here is what I have - but I want to be able to add new file names.
Private Sub HaircutExtract_Click()
On Error GoTo Err_HaircutExtract_Click
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Limit file selection to a single file in dialog box
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Please select one file for target"
' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Access Projects", "*.ADP"
.Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
For Each varFile In .SelectedItems
DoCmd.TransferText acExportDelim, "HaircutExtractSpec", "Haircut
Query", FileName:=varFile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
Exit_HaircutExtract_Click:
Exit Sub
Err_HaircutExtract_Click:
MsgBox Err.Description
Resume Exit_HaircutExtract_Click
End Sub
file. I can figure out how to use the msoFileDialogFilePicker code to select
a file that already exists and write the new data into it. But how do I
allow the user to input a new file name and have the data write out to that.
Here is what I have - but I want to be able to add new file names.
Private Sub HaircutExtract_Click()
On Error GoTo Err_HaircutExtract_Click
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Limit file selection to a single file in dialog box
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Please select one file for target"
' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Access Projects", "*.ADP"
.Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
For Each varFile In .SelectedItems
DoCmd.TransferText acExportDelim, "HaircutExtractSpec", "Haircut
Query", FileName:=varFile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
Exit_HaircutExtract_Click:
Exit Sub
Err_HaircutExtract_Click:
MsgBox Err.Description
Resume Exit_HaircutExtract_Click
End Sub