"Input" statement

M

Michael

Hello -

I'm having some difficulties with the "Input" statement and hoping someone
can tell me what i'm doing wrong.

I need to import a delimited file into an Access 2003 database. The file is
an HL7 medical report in case anyone is familiar with that. Basically it is
pipe delimited, the first row contains records for the "MSH" segment, the
second row contains "EVN" records, etc. Then further down in the report
there are multiple "OBX" lines that contain the actual body of the report.
Each OBX line will need appended to the previous one to form one continuous
report.

It's my understanding that the "Input" statement should open the entire
file, including carriage returns or line feeds. However, Input only opens up
the first line of the file for me. This means that in order to advance
through the file, Access is adding a new record for each line. A sample of
what i'm doing:

Open strPath & strFileName for Input as #1
Input #1, myFile

At this point, myFile is equal only contains the first line of the file.
Any suggestions or tips are GREATLY appreciated.

Thank you!!
 
S

Stuart McCall

Michael said:
Hello -

I'm having some difficulties with the "Input" statement and hoping someone
can tell me what i'm doing wrong.

I need to import a delimited file into an Access 2003 database. The file
is
an HL7 medical report in case anyone is familiar with that. Basically it
is
pipe delimited, the first row contains records for the "MSH" segment, the
second row contains "EVN" records, etc. Then further down in the report
there are multiple "OBX" lines that contain the actual body of the report.
Each OBX line will need appended to the previous one to form one
continuous
report.

It's my understanding that the "Input" statement should open the entire
file, including carriage returns or line feeds. However, Input only opens
up
the first line of the file for me. This means that in order to advance
through the file, Access is adding a new record for each line. A sample
of
what i'm doing:

Open strPath & strFileName for Input as #1
Input #1, myFile

At this point, myFile is equal only contains the first line of the file.
Any suggestions or tips are GREATLY appreciated.

Thank you!!

The behaviour you've witnessed is by design. IOW the Input statement is
intended to read the file line by line. I would recommend reading the whole
file into a string, like this:

Dim f As Integer, b As String

f = FreeFile
Open strPath & strFileName for Binary Access Read As f
b = Space$(LOF(f))
Get #f, , b
Close f

This results in the entire file contents being stored in the variable b. Now
you can use string ops to pull it apart.
 
M

Michael

Thank you for the advice. That solved my problem. I was under the
impression that "Line Input" handled only one line at a time, while "Input"
read the entire file.

Thanks again!!
 
S

Stuart McCall

Michael said:
Thank you for the advice. That solved my problem. I was under the
impression that "Line Input" handled only one line at a time, while
"Input"
read the entire file.

Thanks again!!
<snip>

You're welcome. Glad that solved it for you.

For future reference, Line Input, as you say, is for reading a text file a
line at a time (lines being delimited by carriage returns), whereas Input,
although it too reads the file line by line, it is most often used for
importing comma-separated value files. See help for more info. It'll
probably come in useful someday.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top