Solved

How to Simulate Parameters in an SQL Pass-Through Query

Posted on 2011-03-03
8
317 Views
Last Modified: 2012-05-11
Using MS Access, I am trying to pass a parameter to a SQL Server stored procedure by utilizing a pass-through query.  I found information from http://support.microsoft.com/kb/131534

I am receiving a type mismatch error on line" Set MyRS = MyQry.OpenRecordset()
This is what I am entering in the Immediate window: ?ParamSPT2("500")

Can you help me resolve this?
Your help is appreciated.

Here is the code:  

  Function ParamSPT2(MyParam As String)

        Dim MyDb As Database, MyQry As QueryDef, MyRS As Recordset
         Set MyDb = CurrentDb()
         Set MyQry = MyDb.CreateQueryDef("")

         ' Type a connect string using the appropriate values for your
         ' server.
        MyQry.connect = "ODBC;DSN=EPM_DEV;Description=EPM_Development;UID=abc123;Trusted_Connection=Yes;DATABASE=P Import"
         ' Set the SQL property and concatenate the variables.
         MyQry.SQL = "sp_server_info " & MyParam

         MyQry.ReturnsRecords = True
         Set MyRS = MyQry.OpenRecordset()
         MyRS.MoveFirst

         Debug.Print MyRS!attribute_id, MyRS!attribute_name, MyRS!attribute_value

         MyQry.Close
         MyRS.Close
         MyDb.Close

0
Comment
Question by:psueoc
  • 5
  • 3
8 Comments
 
LVL 15

Expert Comment

by:derekkromm
ID: 35030112
what if you try ParamSPT2("'500'")?

Also, is there only 1 parameter for sp_server_info? Including optionals, etc.
0
 

Author Comment

by:psueoc
ID: 35030167
Still receiving same error using:  ?ParamSPT2("'500'")
0
 
LVL 15

Expert Comment

by:derekkromm
ID: 35030303
what happens if you run "sp_server_info 500" from sql management studio?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:psueoc
ID: 35030394
It completes successfully results: 500      SYS_SPROC_VERSION      9.00.5000:
0
 

Author Comment

by:psueoc
ID: 35030480
Correction:
It completes successfully from the SQL Management Studio.
0
 
LVL 15

Accepted Solution

by:
derekkromm earned 500 total points
ID: 35030512
Review this KB article and see if it applies to you?

http://support.microsoft.com/kb/181542
0
 

Author Comment

by:psueoc
ID: 35030600
Awesome problem solved!  http://support.microsoft.com/kb/181542

Thanks for your help.
0
 

Author Closing Comment

by:psueoc
ID: 35030610
Quick reply to my initial post and persistent to the end.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question