Solved

How to Simulate Parameters in an SQL Pass-Through Query

Posted on 2011-03-03
8
300 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
 

Author Comment

by:psueoc
ID: 35030394
It completes successfully results: 500      SYS_SPROC_VERSION      9.00.5000:
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now