Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input ASCII file into DB

Status
Not open for further replies.

BuilderSpec

Programmer
Dec 24, 2003
383
GB
Type Layout1
UserName As String * 20
StarSign As String * 20
End Type

Dim rec As Layout1
Dim str As String

Function PopulateType()

Open "C:\Signs.txt" For Input As #1
While Not EOF(1)
Input #1, str

Debug.Print "Name = [" & rec.UserName & "]"
Debug.Print "Sign = [" & rec.StarSign & "]"
Wend
Close #1


End Function

Hi all

above is my attempt at reading a record from an ascii file and then trying to overlay the input with a record layout. I read the line into a string ( str ) but how do i then "transfer" or copy that string into "rec", or is there a way using the "input #1" functions that will let me read directly from the file into a "record" type ?

BuilderSpec

 
If records in the text file are one per line (i.e. each record ends with vbCRLF) then you could use Input Line to read a record at a time. Assuming from your structure that the fields are fixed width (i.e. each field is 20 characters long) the you could allocate to the structure:

rec.UserName = Left(str, 20)
rec.StarSign = Right(str, 20)

If you have more fields, then you would need to use the Mid function

rec.Field1 = Left(str, LengthOfField1)
rec.Field2 = Mid(str, LengthOfField1 + 1, LengthOfField2)
etc.
etc.


Hope this helps.
 
thanks

I already thought of that , but there must be something that can effectively say

record = string

and it will overlay the string onto the layout.
 
If you use a delimiter in the file (comma, tab) then you could import this through the import right click and then save the file specification.

To automate importing you would then be able to use the DoCmd.TransferText function in VBA (Look it up in vba help for full list of parameters)

Danny

Never Think Impossible
 

BuilderSpec,

Have a look at this thread181-1085235 too, for
another alternative.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top