• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Importing text file to Access Database

C

Codeblack

#1
Hi,

Does any one know how to import a delimeted text file into access database
using VBscript. Any suggestions is appreciated.

Thanks
 
H

hb21l6

#3
"Codeblack" <Codeblack@xxxxxx> wrote in message
news:F68F65F2-4FEE-4015-BEE5-EE89EFFF074A@xxxxxx

> The data is something like this.
>
> abc.rtd@xxxxxx,unknown,google.com,290447512478,714
>
that depends on how much in depth you want to go with it,

Firstly, you need to read the txt file..

myFile = "C:\mytextFile"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(myFile,1)

If objFSO.FileExists(HFiles) Then
' see if the file exists and open it
Set HFile = objFSO.OpenTextFile(myFile,8, True)
else
' Create a Header file
Set HFile = objFSO.CreateTextFile(myFile, True)
End If


THIS IS HOW YOU MAKE A CONNECTION TO A msACCESS DATABASE

Set dbConn= Server.CreateObject("ADODB.Connection")
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\db2.mdb;Persist Security Info=False"
dbConn.Open(sConnString)
SET rsupdate = server.createObject("adodb.recordset")

Do Until objFile.AtEndOfLine
' here is your line of data.
line=objFile.ReadLine
' you now need to split this line using the Split() object to parse out each
field from the line


SQL = "insert into tbl_name (field1, field2 field3, etc) values ('" & val1 &
"', " & val2 & ", '" & val3 & "')"

SET rsupdate = dbconn.execute(SQL)


Loop

set rsupdate = nothing
set dbconn = nothing



YOU WILL NEED TO ALTER THIS TO SUITE YOUR NEEDS.



Dave