I have a VBA macro running on Excel 2003 to import data from an Access database using ADO with a parametrized command.
Using the same code with Excel 2010 (MS Access is not running) and the same mdb file, the system goes to "non responding" mode and hangs forever. Tracing through the code, the problem occurs at the last step.
Again, no execution issue if I use my old machine with Excel 2003
Below is the code I use to connect to the database.
I do not understand what I am not doing right
Thanks in advance
Olivier
Code:
wsSheet.Range("A1").CurrentRegion.Clear
Set rst = New ADODB.Recordset
MyConn = "Provider=Microsoft.JET.OLEDB.4.0;" & "Data Source=z:\olivier.mdb"
Set cnn = New ADODB.Connection
cnn.Open MyConn
Set cmd = New ADODB.Command
cmd.CommandType = adCmdStoredProc
cmd.ActiveConnection = cnn
cmd.CommandText = "Parametrics"
Set param = cmd.CreateParameter
param.Type = adChar
param.Size = Len(sPO)
cmd.Parameters.Append param
cmd.Parameters(0).Value = sPO
Set rst = cmd.Execute
Using the same code with Excel 2010 (MS Access is not running) and the same mdb file, the system goes to "non responding" mode and hangs forever. Tracing through the code, the problem occurs at the last step.
Again, no execution issue if I use my old machine with Excel 2003
Below is the code I use to connect to the database.
I do not understand what I am not doing right
Thanks in advance
Olivier
Code:
wsSheet.Range("A1").CurrentRegion.Clear
Set rst = New ADODB.Recordset
MyConn = "Provider=Microsoft.JET.OLEDB.4.0;" & "Data Source=z:\olivier.mdb"
Set cnn = New ADODB.Connection
cnn.Open MyConn
Set cmd = New ADODB.Command
cmd.CommandType = adCmdStoredProc
cmd.ActiveConnection = cnn
cmd.CommandText = "Parametrics"
Set param = cmd.CreateParameter
param.Type = adChar
param.Size = Len(sPO)
cmd.Parameters.Append param
cmd.Parameters(0).Value = sPO
Set rst = cmd.Execute