How to create table in mdb from dbf query

Deadly 提交于 2019-12-20 05:10:36

问题


I have a dbf that I would like to copy into a new mdb using VB6.

The following is where I am up to, I can create the new mdb easily enough, however, I thought I could just do a Select query with an INTO to create a new table with the data.

Please note: what I'm assuming is the MSAccess table gets created at the time the sql query gets run.

I get a syntax error in FROM clause. What I was trying to do is manipulate this sql query to do what I need it to:

sql = "INSERT INTO [Table1] SELECT * FROM [source.dbf] IN " & dbfPath

My example vb:

new_mdb = root_directory & "\Temp\LnX.mdb"

Dim conCatalog As ADOX.Catalog
Set conCatalog = New ADOX.Catalog
conCatalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & new_mdb
Set conCatalog = Nothing

Dim db As Database
Dim sql As String
Dim dbfPath As String

Set db = OpenDatabase(new_mdb, dbDriverComplete, False)
dbfPath = "'" & root_directory & "\Core'[dBase IV;]"

sql = "SELECT * FROM [LnX.dbf] IN '" & dbfPath & "' INTO [LnX]"
db.Execute sql

db.Close
Set db = Nothing

回答1:


Ended up with a ADODB connection to the newly created mdb. Then executed this to create the table and data.

sql = "SELECT * INTO [" & table_name & "] " & _
      "FROM [dBase IV;DATABASE=" & sourceDBpath & "].[" & table_name & "]"


来源:https://stackoverflow.com/questions/24879760/how-to-create-table-in-mdb-from-dbf-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!