Import file into Access database

  • Thread starter Thread starter sham
  • Start date Start date
S

sham

Hi to all,

I need to import a file (csv) into an empty access database.

If I do this manually, I would have to :
1) Open access and select get External data
2) Check delimited text
3) Then go to the next tab and select text qualifier " and click box "First
Row Contains Field names"
4) Choose a key
5) Hit the finish button.

Is it possible to automated the above steps? If so how and on what objects?

Sham.
 
¤ Hi to all,
¤
¤ I need to import a file (csv) into an empty access database.
¤
¤ If I do this manually, I would have to :
¤ 1) Open access and select get External data
¤ 2) Check delimited text
¤ 3) Then go to the next tab and select text qualifier " and click box "First
¤ Row Contains Field names"
¤ 4) Choose a key
¤ 5) Hit the finish button.
¤
¤ Is it possible to automated the above steps? If so how and on what objects?

Give the following a try:

Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
& _
"Data Source=C:\Test Files\db1 XP.mdb")

AccessConn.Open()

Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO [ReportFile] FROM
[Text;DATABASE=C:\Documents and Settings\...\My Documents\My Database\Text].[ReportFile.txt]",
AccessConn)

AccessCommand.ExecuteNonQuery()
AccessConn.Close()

You can find info on how to create an index or primary key in the below article:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/acfundsql.asp


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top