We have an Access 2002 frontend and SQL Server 2000 backend.
I am trying to get this function to work but am getting Invalid use of property, when the code gets to cmdSQL.CommandType
Here is the code I have written:
Public Function GetStoredProcedure() As String
On Error GoTo Err_GetStoredProcedure_Click
Dim strConn As String
Dim cnnDB As ADODB.Connection
Dim cmdSQL As New ADODB.Command
Set cnnDB = New ADODB.Connection
strConn = "Driver={SQL Server};" & _
"Server=OurServer;"&_
"Database=DatabaseName;"&_
"Trusted_Connection=Yes"
cnnDB.Open strConn
'Set the connection for the command to your opened connection
cmdSQL.ActiveConnection = cnnDB
'Set the command object type to stored procedure
cmdSQL.CommandType adCmdStoredProc
'Set the stored procedure name
cmdSQL.CommandText = "CreateReferenceID"
'Execute the command
cmdSQL.Execute
'Close the connection
cnnDB.Close
Exit_GetStoredProcedure_Click:
Exit Function
Err_GetStoredProcedure_Click:
MsgBox Err.Description
Resume Exit_GetStoredProcedure_Click
End Function
There are no parameters in the stored procedure.
It would be greatly appreciated if someone could tell me where I have gone wrong.
Thanking you in advance.
Regards
Antony
I am trying to get this function to work but am getting Invalid use of property, when the code gets to cmdSQL.CommandType
Here is the code I have written:
Public Function GetStoredProcedure() As String
On Error GoTo Err_GetStoredProcedure_Click
Dim strConn As String
Dim cnnDB As ADODB.Connection
Dim cmdSQL As New ADODB.Command
Set cnnDB = New ADODB.Connection
strConn = "Driver={SQL Server};" & _
"Server=OurServer;"&_
"Database=DatabaseName;"&_
"Trusted_Connection=Yes"
cnnDB.Open strConn
'Set the connection for the command to your opened connection
cmdSQL.ActiveConnection = cnnDB
'Set the command object type to stored procedure
cmdSQL.CommandType adCmdStoredProc
'Set the stored procedure name
cmdSQL.CommandText = "CreateReferenceID"
'Execute the command
cmdSQL.Execute
'Close the connection
cnnDB.Close
Exit_GetStoredProcedure_Click:
Exit Function
Err_GetStoredProcedure_Click:
MsgBox Err.Description
Resume Exit_GetStoredProcedure_Click
End Function
There are no parameters in the stored procedure.
It would be greatly appreciated if someone could tell me where I have gone wrong.
Thanking you in advance.
Regards
Antony