Solved

How to Simulate Parameters in an SQL Pass-Through Query

Posted on 2011-03-03
8
290 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
Comment Utility
what if you try ParamSPT2("'500'")?

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

Author Comment

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

Expert Comment

by:derekkromm
Comment Utility
what happens if you run "sp_server_info 500" from sql management studio?
0
 

Author Comment

by:psueoc
Comment Utility
It completes successfully results: 500      SYS_SPROC_VERSION      9.00.5000:
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

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

Accepted Solution

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

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

Author Comment

by:psueoc
Comment Utility
Awesome problem solved!  http://support.microsoft.com/kb/181542

Thanks for your help.
0
 

Author Closing Comment

by:psueoc
Comment Utility
Quick reply to my initial post and persistent to the end.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

772 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

12 Experts available now in Live!

Get 1:1 Help Now