Re: Importing MS Office Excel Comma Separated Values Files into a MS Access 2003 database -
05-14-2010
, 02:14 PM
Greetings,
It sounds like what you have is a .cvs file. If this is the case then
you can write a routine using the Open (textfile) function and Line
Input to read in the lines. Or, if coding isn't your thing, you can
search for VBA scripts that can read comma delimited (.csv) files and
implement that into your project. Here is a sample that might work for
you:
Sub ReadCSVfile()
Dim s As String, RS As DAO.Recordset
Set RS = CurrentDb.OpenRecordset("tblText")
Open "C:\1A\test1.csv" For Input As #1
Do While Not EOF(1)
Line Input #1, s
RS.AddNew
RS(0) = s
RS.Update
Debug.Print s
Loop
Close #1
RS.Close
End Sub
This routine reads each line of a .csv file and writes it to a table
("tblText") which only contains one field -- a memo field (incase the
lines contain a lot of text).
The next step is then to parse out each field of data which would be
delimited by commas. You can use the Split function for this.
Sub SplitString1()
Dim str1 As String, str2 As Variant, str3 As Variant
str1 = "a,b,c,d"
str2 = Split(str1, ",")
For Each str3 In str2
Debug.Print str3
Next
End Sub
Then you would write the contents of each line to a 2nd table that would
contain the same number of fields at the source data.
HTH
Rich
*** Sent via Developersdex http://www.developersdex.com *** |