Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select a folder? 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need to pass a report to the word to a especific folder. How can i make it?
 
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) <> &quot;&quot; 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 &quot;Error No &quot; & Err.Number & vbLf & Err.Description
End If
Resume Exit_pbBrowse_Click
End Sub


Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top