Importing data from file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have tracking devices fitted to the company's fleet of vehicles. They write
data to a .pos file.

The .pos file consists of a zero terminated string containing the position
info for every point. These are stored at 128 byte intervals within the file.

How can I import this data into the database? Does VBA support string buffers?

Thanks

Dave
 
Hi David. Here is a import function. This is off the top of my head so
don't chisal it into stone. If you have problems just post. I check the
group 2-3 times a week.

Scott Burke

Function import_SDF(TheFile As String, TheRecordLenght As Integer,
TheInputTable As String)
Dim db As Database
Dim rs As Recordset

Dim Buffer1 As String
Dim FileLenght As Long
Dim TotalRecordCount As Long
Dim I As Integer

Rem Add two to TheRecordLenght
Rem You may need to change this. It deals with the control
Rem charater at the end of a line.
TheRecordLenght = TheRecordLenght + 2

Rem open the table the data is going into.
Set db = CurrentDb()
Set rs = db.OpenRecordset(TheInputTable)

Rem Close anything that maybe open in channel one.
Close #1

Rem Open the file up in channel one.
Open TheFile For Input As #1 Len = TheRecordLenght

Rem Get the lenght of the open file
FileLenght = LOF(1)

Rem Number of records.
TotalRecordCount = FileLenght / TheRecordLenght

For I = 1 To TotalRecordCount
Buffer1 = Input(TheRecordLenght, #1)

Rem Here is where you enter the information into the different fields.
rs.AddNew
rs![pcc_ordnum] = Mid(Buffer1, 1, 20)
rs![ordnum] = Trim(Mid(Buffer1, 21, 20))
rs![Name] = Trim(Mid(Buffer1, 40, 35))
rs![addr1] = Trim(Mid(Buffer1, 73, 35))
rs![addr2] = Trim(Mid(Buffer1, 114, 35))


rs.Update

Next

Rem close everything.
rs.Close
Close #1
End Function
 
Back
Top