Solved

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

Posted on 2004-08-12
5
550 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

Suggested Solutions

Title # Comments Views Activity
vba sql wild card passing in code 3 24
How can I Flash a mandatory field in Access Form? 13 48
Combobox row source 2 20
Binding recordsets to a form 6 26
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

777 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