Exporting MS Access table to text file and appending current date to file name.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mamin
    New Member
    • Apr 2007
    • 5

    Exporting MS Access table to text file and appending current date to file name.

    I have a table that I need to export out to a text fiel, without column headers. I also need to have the file name include currernt date. Can anyone help me? I'm using the following code:


    [B]Public Function CreateFiles()

    Dim db As Database
    Dim rst As Recordset
    Dim m_str As String
    Dim dt_str As String
    Dim y_str As String
    Dim d As Variant
    Dim dir_str As String
    Dim loc As String, fl As String, I As Integer





    d = FreeFile

    m_str = Format(InputBox ("Specify Month", , Month(Date)), "00")
    If m_str = "" Then
    Exit Function
    End If

    dt_str = Format(InputBox ("Specify Day", , Day(Date)), "00")
    If dt_str = "" Then
    Exit Function
    End If


    y_str = InputBox("Speci fy Year", , Year(Date))
    If y_str = "" Then
    Exit Function
    End If
    Set db = CurrentDb



    For I = Len(db.Name) To 1 Step -1
    If Mid(db.Name, I, 1) = "\" Then
    Exit For
    End If
    Next I
    loc = Left(db.Name, I) & "Batches\Pmts_b y_Checks_"



    Set rst = db.OpenRecordse t("PMTS_BY_Chec ks", dbOpenSnapshot)

    Open loc & "PMTS_BY_Checks _" & m_str & dt_str & Right(y_str, 2) & ".txt" For Output As d
    Do

    Print #d, [AccountNumber] & "," & !Amount & "," & !PMTType & "," & ![PaymentDate] & "," & ![Description] & "," & "," & ![InvoiceNum] & "," & ![Check #]
    .MoveNext
    Loop While Not .EOF

    Close d


    End Function


    I get the following error message:

    Comile Error

    External name not defined

    It looks like error near Print #D, [AccountNumber]


    Thank you in advance.
  • pks00
    Recognized Expert Contributor
    • Oct 2006
    • 280

    #2
    How about something simple like this

    DoCmd.TransferT ext acExportDelim, , "PMTS_BY_Checks ", "c:\tsdn\Pmts_b y_Checks_" & Format(Now(), "yyyymmdd") & ".txt", False

    this exports to a folder called c:\tsdn
    datetimestamp is YYYYMMDD

    eg

    filename is Pmts_by_checks_ 20070411

    Comment

    • mamin
      New Member
      • Apr 2007
      • 5

      #3
      Thank you. It worked but the only thing I do not want is quotes around each text field.

      Originally posted by pks00
      How about something simple like this

      DoCmd.TransferT ext acExportDelim, , "PMTS_BY_Checks ", "c:\tsdn\Pmts_b y_Checks_" & Format(Now(), "yyyymmdd") & ".txt", False

      this exports to a folder called c:\tsdn
      datetimestamp is YYYYMMDD

      eg

      filename is Pmts_by_checks_ 20070411

      Comment

      Working...