[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 665
  • Last Modified:

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
0
Anthony Berenguel
Asked:
Anthony Berenguel
  • 4
  • 4
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
Anthony BerenguelAuthor Commented:
thanks, LSMConsulting. Got it working.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now