troubleshooting Question

VBA ADODB.Connection excel syntax error or access violation

Avatar of Bharat Guru
Bharat Guru asked on
Microsoft Excel
2 Comments1 Solution1421 ViewsLast Modified:
some how I'm getting exel syntex error or access voplation error for objMyRs.Open objMyCmd.Execute  

-------------
exec MyStoreprocedure 'UserID'

    Dim prm As ADODB.Parameter
    Set objMyConn = New ADODB.Connection
    Set objMyCmd = New ADODB.Command
    Set objMyRs = New ADODB.Recordset
   
    'Open Connection'
    objMyConn.ConnectionString = "Provider=SQLOLEDB;Data Source=MyServername;User ID=MyUserIS;Password=MyPass;Database=MyDatabaseName;"
    objMyConn.Open
       
    Set objMyCmd.ActiveConnection = objMyConn
    objMyCmd.CommandType = adCmdStoredProc
    objMyCmd.CommandText = "exec MyStoreprocedure"
   
     Set prm = objMyCmd.CreateParameter("UserID", adVarChar, adParamInput, 10, StrUserID)
     objMyCmd.Parameters.Append prm
     objMyCmd.Parameters("UserID").Value = "bpatel"
       
       
   objMyRs.Open objMyCmd.Execute
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros