Hi I am trying to call a stored procedure from VBA, my code is as below:
' SQL Connection
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=REVGOV;Data Source=pdlfslab10"
''''''''''''''''''Some of my parameters from excel goes here which I use as variables in the command text''''''''''''''
conn.Open
Set cmd = New ADODB.Command
cmd.ActiveConnection = conn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "exec MyProc '& FY &', '& Month &', '& VerticalSrNo &','& Vertical &','& LocationSrNo &','& Location &', '& UserName &'"
cmd.Execute
conn.Close
Set conn = Nothing
Set cmd = Nothing
End Sub
But I am getting an error "Syntax Error or Access Violation"
Help Needed!!!!!
' SQL Connection
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=REVGOV;Data Source=pdlfslab10"
''''''''''''''''''Some of my parameters from excel goes here which I use as variables in the command text''''''''''''''
conn.Open
Set cmd = New ADODB.Command
cmd.ActiveConnection = conn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "exec MyProc '& FY &', '& Month &', '& VerticalSrNo &','& Vertical &','& LocationSrNo &','& Location &', '& UserName &'"
cmd.Execute
conn.Close
Set conn = Nothing
Set cmd = Nothing
End Sub
But I am getting an error "Syntax Error or Access Violation"
Help Needed!!!!!