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
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