I'm trying to update an access database from excel with an SQL statement. I've tried ADODB command execution, ADODB connection.execute, and DAO database.execute. The data update is successful, but any time the connection gets closed, excel/vba become unresponsive for 5-10 minutes. We are using Office 2010
This person seems to have had the same problem, but I've tried waiting after executing for a couple minutes to close the connection and it hasn't helped.
VBA ADODB Connection close taking too long - Excel 2010 - Stack Overflow
or
This person seems to have had the same problem, but I've tried waiting after executing for a couple minutes to close the connection and it hasn't helped.
VBA ADODB Connection close taking too long - Excel 2010 - Stack Overflow
Code:
Dim CN As ADODB.Connection
Dim CM As ADODB.Command
Set CN = New ADODB.Connection
CN.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=S:\Mydbaddress\db.accdb"
Set CM = New ADODB.Command
CM.ActiveConnection = CN
CM.CommandText = sql
CM.Execute
Do Until CN.State = 1
Debug.Print CN.State
DoEvents
Loop
Set CM = Nothing
CN.Close 'Hangs up here
Set CN = Nothing
or
Code:
Dim DB As DAO.Database
Set DB = Workspaces(0).OpenDatabase("S:\OSK-Share\DEPT\ILS\IPSQCBE1.accdb")
DB.Execute sql, dbFailOnError
DB.Close 'Hangs up here
Set DB = Nothing