?
Solved

Fixed File Import

Posted on 2000-01-10
2
Medium Priority
?
180 Views
Last Modified: 2010-05-02
Is there a way to import a fixed width text file into a access database table?
0
Comment
Question by:jrcp
  • 2
2 Comments
 
LVL 6

Expert Comment

by:anthonyc
ID: 2339572
yes...  You can do it with access, but if you do not want to require that access is on the machine, you can do this:

Let's assume you have 3 fields in your text file.  A name (30 chars), birthdate (10 char) and a score (3 char)  you can do this  (all off the cuff, forgive me if I make a typo or something)

type PlayerRecord
  szName  as string * 30
  szDate  as string * 10
  szScore as string * 3
end type
private const mc_lRecLen = 43

private sub ReadAndInsert(szFileName as string, rsTable as recordset)
  dim nFile     as integer
  dim prRec     as PlayerRecord
  dim lRecCt    as Long
  dim lI        as long

  nFile = freefile
  Open szFileName for Input as #nFile
 
  lrecct = lof(nfile) \ mc_lRecLen

  for lI = 1 to lRecCt
    get #nFile, lI, prRec

    rsTable.Addnew
    rsTable!PlayerName = prRec.szName
    rsTable!BirthDate = cdate(prRec.szDate)
    rsTable!Score = val(prRec.szScore)
    rsTable.Update
  next ni

  close #nfile 'we read the entire file
end sub
0
 
LVL 6

Accepted Solution

by:
anthonyc earned 400 total points
ID: 2340039
oops that was an answer!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question