ULSWK
New member
- Joined
- Oct 15, 2024
- Messages
- 3
- Reaction score
- 0
- Points
- 1
- Excel Version(s)
- Office 365
Hi all,
I'm using an Access Database as Source for Power Pivot in my Excel Sheet.
In this example the access database is this: "C:\Temp\Test.accdb"
Trying to change this connection to eg. "C:\Temp\Test2.accdb", I receive error 1004.
Any clue how to change an OLEDB Access Connection as source for a pivot table?
Sub ChangeConnection()
Dim wbk As Workbook
Dim cn As WorkbookConnection
Dim oledbCn As OLEDBConnection
Dim strConn$
Set wbk = ThisWorkbook
For Each cn In wbk.Connections
If cn.Type = xlConnectionTypeOLEDB Then
Set oledbCn = cn.OLEDBConnection
strConn = oledbCn.Connection
Debug.Print strConn
' Result:
' OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Temp\Test.accdb;Persist Security Info=false
oledbCn.Connection = "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Temp\Test2.accdb;Persist Security Info=False;"
' Result :
' ERROR 1004: Application or object oriented error
End If
Next
End Sub
I'm using an Access Database as Source for Power Pivot in my Excel Sheet.
In this example the access database is this: "C:\Temp\Test.accdb"
Trying to change this connection to eg. "C:\Temp\Test2.accdb", I receive error 1004.
Any clue how to change an OLEDB Access Connection as source for a pivot table?
Sub ChangeConnection()
Dim wbk As Workbook
Dim cn As WorkbookConnection
Dim oledbCn As OLEDBConnection
Dim strConn$
Set wbk = ThisWorkbook
For Each cn In wbk.Connections
If cn.Type = xlConnectionTypeOLEDB Then
Set oledbCn = cn.OLEDBConnection
strConn = oledbCn.Connection
Debug.Print strConn
' Result:
' OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Temp\Test.accdb;Persist Security Info=false
oledbCn.Connection = "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Temp\Test2.accdb;Persist Security Info=False;"
' Result :
' ERROR 1004: Application or object oriented error
End If
Next
End Sub