Access VBA calling stored procedure issues

Hello,

I've read the threads about how to call stored procedures within access vba and I took an example and tried to make it work for me. However, I keep getting errors messages. I'm hoping an expert can sort me out.

Here's my code:
 
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
                        
With cmd
  .ActiveConnection = CurrentProject.Connection
  .CommandType = adCmdStoredProc
  .CommandText = "sp_getMasterFileForPDF "
  .Parameters.Append .CreateParameter("@PDFname", adVarChar, adParamInput, 200, PDF_NAME)
  .Execute
End With

Open in new window


I get the following error message when i try to run the code:
The Microsoft Jet database engine cannot find the input table or query 'sp_getMasterFileForPDF'.  Make sure it exists and that its name is spelled correctly.

However, if I add a dot before my stored precudre name (".sp_getMasterFileForPDF") then I get the following error:
Expected query name after EXECUTE.

I've never tried calling a stored procedure before, so I am very new to the concept. Any help is appreciated.

thanks!
Anthony
LVL 10
Anthony BerenguelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Do you need to have anything returned from the SP? If not, the quickest way to do this is just calling the SP directly:

CurrentProject.Connection.Execute "EXEC sp_getMasterFileForPDF  @PDFName='" & YourPDFNameValue & "'"
0
 
Anthony BerenguelAuthor Commented:
Remember I am really new to SQL and stored procedures.

Anyway, the store procedure is doing a select query, and i'd like to use the results of that select query to populate a recordset.
0
 
Anthony BerenguelAuthor Commented:
LSMConsulting,

i tried you statement and received the following,

"The Microsoft Jet database engine cannot find the input table or query 'sp_getMasterFileForPDF'.  Make sure it exists and that its name is spelled correctly."

I know for sure that is what the store procedure is called. Am I not connecting to SQL correctly?

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Is your database connected to the SQL Server (i.e. linked tables)? If it's not, you'll have to build a connection and connect to that server.
0
 
Anthony BerenguelAuthor Commented:
Yes, my db has linked tables from the SQL server.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Note to return a Recordset, you'd do this:

Dim rst As ADODB.Recordset
Dim con As ADODB.Connection

Set con = New ADODB.Connection
con.Open "Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;"

Set rst = New ADODB.Recordset
Set rst = con.Execute("EXEC sp_getMasterFileForPDF  @PDFName='" & YourPDFNameValue & "'", , acCmdStoredProc )

Connection String examples here: http://www.connectionstrings.com/sql-server-2008
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
If linked tables, then you already have a connection to the server (assuming you're only connected to that one server). If so, you might try this:

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
Set rst = CurrentProject.Connection.Execute("EXEC sp_getMasterFileForPDF  @PDFName='" & YourPDFNameValue & "'", , acCmdStoredProc )

If that doesn't work, you'll have to build your connection as shown previously.
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
Anthony BerenguelAuthor Commented:
thanks, LSMConsulting. Got it working.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.