Hi,
I am using Access 2010 and have the following code on my form load which should execute a stored procedure, unfortunately I am receiving an error message on the cmd.Execute line 'Run time error 3709 The connection cannot be used to perform this operation. It is either closed or invalid in the context. '
I have tested the code without the command and the connection does work.
Option Compare Database
Private Sub Form_Load()
Dim cnn As ADODB.Connection
Dim strcnn As String
Dim cmd As New ADODB.Command
Set cnn = New ADODB.Connection
strcnn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=StepSample;Data Source=CONNECTION\NAMEOFCONNECTION"
cnn.ConnectionString = strcnn
cnn.Open CurrentProject.Connection
cmd.CommandText = "[myprocedurename]"
cmd.CommandType = adCmdStoredProc
cmd.Execute
cnn.Close
Set cnn = Nothing
End Sub