Results 1 to 3 of 3
  1. #1
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283

    Importing File and Export it With same file name

    Hello,



    I am confused on how once I have imported a file with the file path and name then be able to write code to export it back out to the same path and file name.

    I will show you the code I have below:

    Public Function GetFile() As Variant
    Dim dialog As Object
    Dim pickedfile As Boolean
    Set dialog = Application.FileDialog(3)
    GetFile = Null
    With dialog
    .InitialFileName = \\Hello\
    .AllowMultiSelect = False
    .Title = "Please select file for import"
    .Filters.Clear
    .Filters.Add "Text Files", "*.TXT; *.CSV"
    pickedfile = False
    pickedfile = .Show
    If pickedfile Then
    GetFile = .SelectedItems.Item(1)
    End If

    End With
    End Function

    And here is the import code


    Dim Day1File As Variant
    Dim Str As String
    DoCmd.SetWarnings False
    'Imports Daily Letter file you choose

    Day1File = GetFile()
    If IsNull(Day1File) Then
    MsgBox "Nothing was selected", vbOKOnly
    Else
    Str = "DELETE * FROM Daily_Letters"
    DoCmd.RunSQL (Str)
    DoCmd.TransferText _
    TransferType:=acImportFixed, _
    SpecificationName:="DOC1", _
    TableName:="Daily_Letters", _
    FileName:=Day1File, _
    HasFieldNames:=False

    MsgBox "The Daily Letters File has been uploaded!"
    End If

    And this is what I tried using to export the file back out:
    DoCmd.TransferText acExportFixed, "DOC1", _
    "Daily_Letters", Day1File

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    use a form, with a text box for the filepath.

    txtPath = GetFile()

    then process your data, then export it with the text box

    filename:= me.txtpath

  3. #3
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    Thanks, I got it to work!

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

Similar Threads

  1. Replies: 4
    Last Post: 09-09-2015, 12:10 PM
  2. Export Access table data to flat file (txt file)
    By edmscan in forum Import/Export Data
    Replies: 3
    Last Post: 06-17-2015, 12:03 PM
  3. Replies: 3
    Last Post: 02-05-2014, 04:25 AM
  4. Replies: 13
    Last Post: 12-12-2013, 07:22 PM
  5. Importing file directly from a Sharepoint file (not list)
    By jstoler in forum Import/Export Data
    Replies: 1
    Last Post: 06-28-2013, 01:44 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