Sam,
It's late, and I don't have a lot of time right now ... but this should get
you started.
Try using the "Line Input" method to read the text from the text file, one
line at a time.
You know that the colon is the delimiter that seperates the Field Name from
the Data, so use the Left and Mid functions to sperate the string into 2
variables as I have below.
You can then add further code to open a recordset on the table that you wish
to populate with the imported data.
I'd try using a Select Case statement on the "strField" variable to determin
which field "strData" belongs in, then poke it in.
************************************************** *******
Private Sub cmdImportText_Click()
Dim TextLine
Dim strField As String
Dim strData As String
Open "C:\TEMP\Names.txt" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.
TextLine = Trim(TextLine) 'Get rid of any leading or trailing spaces
strField = Left(TextLine, InStr(1, TextLine, ":") - 1)
strData = Mid(TextLine, InStr(TextLine, ":") + 1)
Debug.Print "This is the original line of text ... " & TextLine '
Print to Debug window.
Debug.Print "This is the field name ... " & strField
Debug.Print "This is the data ... " & strData
Debug.Print "" 'Print a blank line for spacing purposes
Loop
Close #1 ' Close file.
End Sub
************************************************** *******
This is the output from Debug (Intermediate) Window below:
________________________________________________
This is the original line of text ... Name:John Doe
This is the field name ... Name
This is the data ... John Doe
This is the original line of text ... Title:Grunt
This is the field name ... Title
This is the data ... Grunt
This is the original line of text ... ID:314159
This is the field name ... ID
This is the data ... 314159
This is the original line of text ... Name:Jane Doe
This is the field name ... Name
This is the data ... Jane Doe
This is the original line of text ... Title:Queen-Bee
This is the field name ... Title
This is the data ... Queen-Bee
This is the original line of text ... ID:271828
This is the field name ... ID
This is the data ... 271828
--
HTH,
Don
=============================
Use
My*****@Telus.Net for e-mail
Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)
I'm an Access97 user, so all posted code
samples are also Access97- based
unless otherwise noted.
Do Until SinksIn = True
File/Save, <slam fingers in desk drawer>
Loop
================================
"Sam Lazarus" <xa*******@hotmail.com> wrote in message
news:26**************************@posting.google.c om...
I need to import data from a website, but the text is arranged badly:
Name:John Doe
Title:Grunt
ID:314159
Name:Jane Doe
Title:Queen-Bee
ID:271828
etc...
I tried importing the data with the Get External Data (from a text
file) using the colon as a delimiter but (obviously) I just got two
useless columns. I have limited experience with SQL, VB, Access, so
does anyone know an easy way to do this? Or even a hard way? Thanks
in advance.
--sam