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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set a default file location for the 'output to' function

Status
Not open for further replies.

MISMonkey

MIS
Jun 11, 2003
32
GB
I have a report that is currently output as a snapshot using the docmd.outputo function (something like: DoCmd.OutputTo acOutputReport, "rptName", "Snapshot"). I'm using this rather than 'save as' because it is a convenient way to produce the snapshot format I need. What it doesn't seem to allow me to do it set the default folder location in the save dialogue box. I want the dialogue box to open and point to a folder I specify so uses don't have to navigate their themselves.

I love deadlines. I like the whooshing sound they make as they fly by. (Douglas Adams)
 
Is this what you need?

Code:
Function FindSnapshotReports(strSearchPath) As String
On Error GoTo Errorhandler

    Dim msaof As MSA_OPENFILENAME
    
    msaof.strDialogTitle = "Save this Report as Snapshot Format"
    msaof.strInitialDir = strSearchPath
    msaof.strFilter = MSA_CreateFilterString("Snapshot Files (*.snp)", "*.snp")
    
    MSA_GetOpenFileName msaof
    
    FindSnapshotReports = Trim(msaof.strFullPathReturned)
    
    Exit Function
    
Errorhandler:
    Call Error_Display_Vars(Err, Application.CurrentObjectName)
    
End Function


Code:
Function SaveSnapshotReports()
On Error GoTo Errorhandler

    Dim strSearchPath As String
    Dim strFolderName As String
    Dim strOutputFormat As String
    Dim strLastChars As String
    
    Dim msg, style
    
    strSearchPath = "C:\My Documents"
    
    strFolderName = FindSnapshotReports(strSearchPath)

    If Len(strFolderName) = 0 Then
        msg = "Save of Report cancelled!"
        style = vbOKOnly + vbInformation
        MsgBox msg, style
        Exit Function
    Else
        strOutputFormat = "Snapshot Format"
        
        strLastChars = Mid(strFolderName, Len(strFolderName) - 2, 3)
        If strLastChars <> "snp" Then
            strFolderName = strFolderName & ".snp"
        End If
        
        DoCmd.OutputTo acOutputReport, , strOutputFormat, strFolderName
    End If
    
    Exit Function
    
Errorhandler:
    Call Error_Display_Vars(Err, Application.CurrentObjectName)
    
End Function
 
Outpu to has an option to set the path
see "OutputTo Method" vba help
Code:
OutputTo(ObjectType, ObjectName, OutputFormat,[b] OutputFile[/b], AutoStart, TemplateFile, Encoding)

________________________________________________________
Zameer Abdulla
Help to find Missing people
Take the first step in faith. You don't have to see the whole staircase, just take the first step.
(Dr. Martin Luther King Jr.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top