Solved

Execute parameterized stored procedure using VBA, not ADP, not passthrough

Posted on 2004-08-12
5
551 Views
Last Modified: 2008-01-09
My apologies if this has already been answered, but all of the solutions I could find referred to ADP or passthrough queries, neither of which is an option for this particular scenario.

I have a MS Access database which is mainly linked tables to several SQL server databases.  One of the ODBC connections is called intlDB.  I have a stored procedure called spCreateGroup which takes three parameters - groupID (integer), sOrder (integer), eOrder(integer).  

How can I execute this stored procedure such that groupID, sOrder, and eOrder are populated via a MS Access form?  Pay me a thousand dollars if I'm wrong, but passthrough queries do not accept Access forms parameters, right?
0
Comment
Question by:eatham111
  • 3
  • 2
5 Comments
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 total points
ID: 11788225
This should do the trick

    Dim dbs1 As DAO.Database, qdf1 As DAO.QueryDef
    Set dbs1 = CurrentDb
        strconnect = "your Connection string'
    Set qdf1 = dbs1.CreateQueryDef("")
        qdf1.Connect = strconnect
        qdf1.ReturnsRecords = False
        qdf1.SQL = "spCreateGroup " & me!groupID & "," & me!sOrder & "," & Me!eOrder
                                       
    qdf1.Execute

qdf1.Close
dbs1.Close
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 11788289

you should also add at the end

set qdf1 =  nothing
set dbs1 = nothing
0
 

Author Comment

by:eatham111
ID: 11788436
It is giving me the error "Invalid connection string in pass-through query."

on this line:

qdf1.SQL = "spCreateGroup " & Me!newgroup & "," & Me!fromOrder & "," & Me!toOrder

My connection string is:

Driver={SQL Server};Server=trg1sql;Database=dbClub;UID=******;PWD=*********;

I know my UID and pwd to be correct - do you see any problems other than that?  I c&p'd your code directoy other than that.
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 11788571
I think that's because you need to being using odbc and not native sqlserver (which is adp land)

try an odbc connection string

ODBC;DSN=dbClub;UID=******;PWD=*********;DATABASE=Orders
0
 

Author Comment

by:eatham111
ID: 11788624
Perfect.  That was it - thanks!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

830 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