Results 1 to 3 of 3

EOF not correctly identifying the correct data. Issue with LF's

  1. #1
    craig1988 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2014

    EOF not correctly identifying the correct data. Issue with LF's

    Hi all

    I am trying to read a text file into an array, however the EOF appears to be stopping before the End of File...

    I have figured out that each line of the text file is finished with a LF and I think I need a CRLF for the EOF to recognise further data.

    I am using the code below which catered for the same input text file with a CRLF at the end of each line.

    I suppose I am trying to replace the LF's with CRLF's. Is there any way to manipulate the below code?

    iFileNum = FreeFile
    Open FileName For Input As iFileNum
    x = 0
    ReDim Preserve sLine(x)
    Do Until EOF(iFileNum)
        Line Input #iFileNum, sLine(x)
        x = x + 1
        ReDim Preserve sLine(x)
    Close iFileNum

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    The Great Land

    Code uses Split() function to parse string to an array.
    Public Sub ImportTextFile_new()
         Dim the_file As String
         Dim LineData As String
         Dim ICDraw As String
         Dim cnn As ADODB.Connection
         Dim rs As ADODB.Recordset
         Dim strSQL As String
         Dim x As Integer
         Dim aryICDraw As Variant
         Set cnn = CurrentProject.Connection
         Set rs = New ADODB.Recordset
         ' Open the text file
         the_file = open_dialog
         Open the_file For Input As #1
         ' Open the table to insert the text file into
         strSQL = "Select * from local_file"
         rs.Open strSQL, cnn, adOpenDynamic, adLockOptimistic
         ' Read a line of data.
         Line Input #1, LineData
         ICDraw = Trim(LineData)
         Close #1
         aryICDraw = Split(ICDraw, vbLf)
         For x = 0 To UBound(aryICDraw)
             rs!the_code = aryICDraw(x)
         Next x
         Set rs = Nothing
         Set cnn = Nothing
    End Sub
    To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression. Attachment Manager is below Advanced editor window, click Go Advanced below Quick Reply window.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Ontario, Canada
    I question the use of iFileNum as a variable but trying to use Input against #iFileNum. Would think they should be the same name. Then again, you say it works elsewhere...
    - "doesn't work" is no help. Post err msgs and where.
    - Use code tags for code/sql. Implement changes in copies of your database.
    Code isn't smart. It does what you ask with what you give it.

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

Similar Threads

  1. Replies: 17
    Last Post: 08-28-2017, 05:25 PM
  2. Replies: 10
    Last Post: 06-03-2013, 09:24 AM
  3. Replies: 11
    Last Post: 04-19-2012, 02:28 PM
  4. Can System Restore correct Form Size issue
    By fordtough in forum Forms
    Replies: 0
    Last Post: 04-12-2011, 01:56 PM
  5. Identifying new data
    By manicamaniac in forum Programming
    Replies: 5
    Last Post: 04-28-2010, 10:08 AM

Posting Permissions

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