JackDanIce
Well-known Member
- Joined
- Feb 3, 2010
- Messages
- 9,922
- Office Version
- 365
- Platform
- Windows
Hi,
Due to large amounts of data, I'm working on a system with an Excel front-end and Access as data store.
For proof of concept/testing, I've successfully written code to read data from a given table with a specific field value, however, I'm struggling to write code (late biding) that pushes data to an Access DB table
When I run below, error message is "Syntax error in FROM clause", I suspect I'm not defining the data source correctly (see red below).
Struggling to find relevant answer online I can adapt, please can someone help correct? TIA, Jack
Due to large amounts of data, I'm working on a system with an Excel front-end and Access as data store.
For proof of concept/testing, I've successfully written code to read data from a given table with a specific field value, however, I'm struggling to write code (late biding) that pushes data to an Access DB table
When I run below, error message is "Syntax error in FROM clause", I suspect I'm not defining the data source correctly (see red below).
Struggling to find relevant answer online I can adapt, please can someone help correct? TIA, Jack
Rich (BB code):
Sub Write_Data()
Dim cn As Object: Set cn = CreateObject("ADODB.Connection")
Dim rs As Object
Dim strAdd As String: strAdd = Data_String_Address
Dim strda() As Variant: strda = Database_Params
With cn
.Open strda(1) & ";Data Source=" & strda(2)
.Execute Write_Query, , 1
.Close
End With
Set cn = Nothing: Set rs = Nothing: Erase strda
End Sub
Private Function Database_Params() As Variant
Dim a As Variant: ReDim a(1 To 2)
a(1) = "Provider=Microsoft.ACE.OLEDB.12.0"
a(2) = Range("Database_Path").Text
Database_Params = a: Erase a
End Function
Private Function Write_Query()
Dim msg As String: msg = "[Excel8.0;HRD=YES;DATABASE=" & ActiveWorkbook.FullName & "]." & Data_String_Address
Write_Query = "INSERT INTO tbl_Data_ORIG SELECT * FROM " & msg
End Function
Private Function Data_String_Address() As String
With Sheets("Data")
Data_String_Address = .Name & "!" & .Cells(2, 1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row - 1, 11).Address
End With
End Function
Last edited: