Results 1 to 2 of 2
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    allow user to select save location for file my code creates

    I have created several variables and I then output those variables to a text file. However, I would like to allow the user to select the location and right now I just have it going to a fixed location. I have seen a lot of code on how to get the Windows save dialogue I am just not sure how to integrate it with my code so it will save my file.



    The save part of my code:
    Code:
    Dim RS As DAO.Recordset
    Dim objFile As Object, TextFile As Object
    Dim TextRecord As NameofRecordP
    Set RS = CurrentDb.OpenRecordset("q_MonthlyInvoices")
    Set objFile = CreateObject("Scripting.FileSystemObject")
    'Set TextFile = objFile.CreateTextFile("D:\MonthlyInvoice.txt", True)

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Add this function to pick files ....
    be sure to add the reference: Microsoft Office xx.0 Object Library, in vbe menu, TOOLS, REFERENCES

    usage:
    vFile = UserPick1File("C:")
    If vFile <> "" Then
    'do something here
    End If

    Code:
    Public Function UserPick1File(Optional pvPath)
    Dim strTable As String
    Dim strFilePath As String
    Dim sDialog As String, sDecr  As String, sExt As String
    
    '===================
    'YOU MUST ADD REFERENCE : Microsoft Office xx.0 Object Library, in vbe menu, TOOLS, REFERENCES
    '===================
    With Application.FileDialog(msoFileDialogFilePicker)   
        .AllowMultiSelect = False
        .Title = "Locate a file to Import"
        .ButtonName = "Import"
        .Filters.Clear
        .Filters.Add "Excel Files", "*.xls;*.xlsx"
        .Filters.Add "All Files", "*.*"
        .InitialFileName = "c:\"
        .InitialView = msoFileDialogViewList    'msoFileDialogViewThumbnail
        
            If .Show = 0 Then
               'There is a problem
               Exit Function
            End If
        
        'Save the first file selected
        UserPick1File = Trim(.SelectedItems(1))
    End With
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. User pick location to save expoerted data
    By MrDummy in forum Import/Export Data
    Replies: 6
    Last Post: 03-29-2016, 03:04 PM
  2. Replies: 1
    Last Post: 03-10-2016, 04:12 PM
  3. Exporting file to select location
    By MTSPEER in forum Programming
    Replies: 11
    Last Post: 02-09-2016, 09:49 AM
  4. Replies: 4
    Last Post: 01-24-2016, 07:41 PM
  5. Save file as a different user to a network folder
    By rstruck in forum Programming
    Replies: 4
    Last Post: 05-10-2014, 04:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums