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

    better to export from spec or create export in VB

    I have a table that I want to export to 500 byte file. I dont need all the fields and I dont see a way to select some fields to not export like the option on the import specification.

    Is there a way to use VB to export certain fields from a table or query to a flat 500 byte fixed length file. I will need to be able to specify the number of characters for each field and have them be blank if there is no value there.


    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Build a query of ONLY the fields you want to export.
    export THAT query.

  3. #3
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Thank you that works well.

    I also found this code

    Code:
    Public Type NameofRecord
      VarRecordFormat As String * 5
      VarBillingInvoicingParty As String * 4
      VarBilledParty As String * 4
      
    End Type
     
    Public Sub OutputTextfile()
    Dim rs As DAO.Recordset
    Dim objFile As Object, TextFile As Object
    Dim TextRecord As NameofRecord
    Set rs = CurrentDb.OpenRecordset("q_500ByteExport")
    Set objFile = CreateObject("Scripting.FileSystemObject")
    Set TextFile = objFile.CreateTextFile("C:\tmp\export.txt", True)
    Do Until rs.EOF
      With TextRecord
        .VarRecordFormat = CStr(rs![RecordFormat])
        .VarBillingInvoicingParty = CStr(rs![BillingInvoicingParty])
        .VarBilledParty = CStr(rs![BilledParty])
        
        TextFile.WriteLine (.VarRecordFormat & .VarBillingInvoicingParty & .VarBilledParty)
      End With
      rs.MoveNext
    Loop
    rs.Close
    TextFile.Close
    End Sub
    It works like I want but the problem is that if there is a null value in any of the fields it does not work. Does anyone know how to get this to work with null fields?
    Thanks

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    The CStr() function errors on Null, as do all conversion functions.

    But if exporting Null is an issue, handle possible Null with Nz() function. Provide some alternate value:

    Nz(rs!RecordFormat, "none")

    The Nz() function results in a string entity and CStr() is unnecessary.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Thanks the Nz seems to be working. The problem with just using the query is that if the field was blank it didnt keep the specified number of characters and a file that should have been 500 chars was only 137 because a lot of the fields are blank.

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

Similar Threads

  1. Object not found when using export spec
    By ctlogistics in forum Import/Export Data
    Replies: 2
    Last Post: 05-07-2014, 10:38 AM
  2. Replies: 2
    Last Post: 06-07-2013, 11:20 AM
  3. Replies: 6
    Last Post: 05-31-2013, 07:46 PM
  4. Export Spec Type
    By bcn1988 in forum Programming
    Replies: 1
    Last Post: 12-13-2012, 09:05 AM
  5. Replies: 1
    Last Post: 04-30-2012, 05:10 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