Hi!
You can use Common Dialog control for setting of file location:
Create Common Dialog control on form and name it cmnDialog. Create command button on form and name it pbBrowse. Copy following codes into codes window.
Public strOutputFileName As String 'Default output File name
'------------------------
Private Sub pbBrowse_Click()
On Error GoTo Err_pbBrowse_Click
Dim strFilter As String
Dim strFileName As String
Dim strOutputDocName As String
Dim objDialog As Object
Set objDialog = Me.cmnDialog.Object
strOutputDocName = "MyReportName"
strFilter = "Rich Text Documents|*.rtf"
With objDialog ' Ask for new file location.
.DialogTitle = "Save Report As..."
.Filter = strFilter
.FileName = strOutputFileName
.CancelError = True
.FilterIndex = 1
.flags = &H4 Or &H2 Or &H800 Or &H400 'cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist
.ShowSave
' If user responded, put selection into textbox on form.
If Len(.FileName) > 0 Then
strOutputFileName = .FileName
If Dir(strOutputFileName) <> "" Then
Kill strOutputFileName
End If
'Save record in rich text format
DoCmd.OutputTo acOutputReport, strOutputDocName, acFormatRTF, strOutputFileName, True
End If
End With
Exit_pbBrowse_Click:
Exit Sub
Err_pbBrowse_Click:
If Err.Number <> 32755 Then 'An error No 32755 is generated
'when the user chooses the Cancel button.
MsgBox "Error No " & Err.Number & vbLf & Err.Description
End If
Resume Exit_pbBrowse_Click
End Sub
Aivars