ClimoC
Well-known Member
- Joined
- Aug 21, 2009
- Messages
- 584
Hello,
diving into cross access/excel stuff here. Well, not really, but I'm using disconnected ADO Record Sets to index my massive worksheet tables (30,000+ rows). The whole thing runs beautifully.
However I now want to be able to merge/pull/export/import different 'Data' sheets around, so for size and future-proofing (as other side of tech might pick these up in the future), I want to save them out as an .mdb
I've gotten my head around record sets pretty well, but have never bothered tinkering with Access type stuff. I'm aware that there's a very simple Access function/method to 'slurp' up entire sheets in one go. Thing is, I don't have Access on the machine, and neither do/will the users of the XL-based 'app' I've made.
I've managed to get this far:
After creating the DB file on my C Drive, I then run the 'Adddata', and I get a window pop up saying "Data Link properties" and it creates a new workbook behind it.
Firstly, I don't want to have a window prompt come up (so some parameters I can set upon creation perhaps?), and secondly, when I click "OK" on the window, I get an Excel error "This data source contains no visible tables"
Anyone see where I've gone wrong? I really didn't think this would be that difficult - but I'm clearly struggling!
Thanks
C
diving into cross access/excel stuff here. Well, not really, but I'm using disconnected ADO Record Sets to index my massive worksheet tables (30,000+ rows). The whole thing runs beautifully.
However I now want to be able to merge/pull/export/import different 'Data' sheets around, so for size and future-proofing (as other side of tech might pick these up in the future), I want to save them out as an .mdb
I've gotten my head around record sets pretty well, but have never bothered tinkering with Access type stuff. I'm aware that there's a very simple Access function/method to 'slurp' up entire sheets in one go. Thing is, I don't have Access on the machine, and neither do/will the users of the XL-based 'app' I've made.
I've managed to get this far:
Code:
Public Sub CreateAccessDatabase()
'----------------------------------------------------------------
Dim oADOCat As Object
Dim oTable As Object
Set oADOCat = CreateObject("ADOX.Catalog")
oADOCat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & dbpath & ThisWorkbook.Sheets("GridData").Range("B44").Value & ".mdb"
Set oTable = CreateObject("ADOX.Table")
' Create a new Table object.
With oTable
.Name = ThisWorkbook.Sheets("GridData").Range("B44").Value
' Create fields and append them to the
' Columns collection of the new Table object.
With .Columns
.Append "Field1", adVarChar, 6
.Append "Field2", adVarChar, 160
.Append "Field3", adVarChar, 80
'etc etc, 27 columns total
End With
End With
Set oADOCat = Nothing
End Sub
Public Sub AddData()
Dim oConn As Object
Dim oRS As Object
Dim sSQL As String
Dim tbl As String
Dim dbpath As String, dbConnectStr As String
tbl = ThisWorkbook.Sheets("GridData").Range("B44").Value
dbpath = "C:\" & tbl & ".mdb"
dbConnectStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath & ";"
Set oConn = CreateObject("ADODB.Connection")
sSQL = "INSERT INTO " & tbl & " SELECT * FROM [$DataA2:AA" & ThisWorkbook.Sheets("Data").Range("A65000").End(xlUp).Row & _
"] IN '" & dbpath & "' 'Excel 8.0;HDR=No;'"
With oConn
.Open = dbConnectStr
.Execute sSQL
End With
oConn.Close
Set oConn = Nothing
End Sub
After creating the DB file on my C Drive, I then run the 'Adddata', and I get a window pop up saying "Data Link properties" and it creates a new workbook behind it.
Firstly, I don't want to have a window prompt come up (so some parameters I can set upon creation perhaps?), and secondly, when I click "OK" on the window, I get an Excel error "This data source contains no visible tables"
Anyone see where I've gone wrong? I really didn't think this would be that difficult - but I'm clearly struggling!
Thanks
C
Last edited: