Solved

How to Simulate Parameters in an SQL Pass-Through Query

Posted on 2011-03-03
8
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

749 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