Solved

Help with passing 2 variables to Stored Procedure

Posted on 2004-09-16
4
263 Views
Last Modified: 2012-08-14
My application is a Access 2000 front end and SQL server backend.  I have a stored procedure on the server that will accept 2 variables.  From my Front End I have a form with 2 comboboxes that pass that data along.  I have been successful at passing one variable, but 2 is giving me grief.  Here is my module...

    'Set up the DAO for the pass-through SQL query
    Dim db As Database
    Dim MyQueryDef As QueryDef
    Dim SQLString As String
    Dim SPTQueryName As String
    Dim msg As String
   
    Set db = CurrentDb()
    db.QueryTimeout = 240
    SPTQueryName = "qrySponsorReportByDivision_SQL"
    If ObjectExists("Queries", SPTQueryName) = True Then
        db.QueryDefs.Delete SPTQueryName
        db.QueryDefs.Refresh
    End If
    Set MyQueryDef = db.CreateQueryDef(SPTQueryName)
   
    MyQueryDef.Connect = IMO_ODBCConnectionString
   
    'Now is a good time to display the Project Manager Choice Selection Screen.
    If intDivision = 0 Then
        DoCmd.OpenForm "frmSponsorReportByDivision", acNormal, , , acFormEdit, acDialog
    End If
       
    'Set the SQL property and concatenate the variables
    If intDivision <> 0 Then
 I NEED HELP HERE ----->      SQLString = "upSponsorReportByDivision" & "'" & intDivision & "' '" & intSponsor & "'"
        MyQueryDef.SQL = SQLString
        MyQueryDef.ReturnsRecords = True
        MyQueryDef.Close
        db.Close
        DoCmd.OpenQuery SPTQueryName, acViewNormal
    Else
        MyQueryDef.ReturnsRecords = False
        MyQueryDef.Close
        db.Close
    End If

What am I doing wrong?  I have tried to seperate those 2 variables with comma's and that didn't work either.  

Thanks!
Dark
0
Comment
Question by:darkmagneto
  • 3
4 Comments
 
LVL 12

Expert Comment

by:pique_tech
ID: 12079239
SQLString = "upSponsorReportByDivision " & "'" & intDivision & "', '" & intSponsor & "'"
                                                           ^^                              ^
                                                    You need a space here        and a comma here

I'm assuming the sp your calling is on the SQL server.
0
 
LVL 12

Accepted Solution

by:
pique_tech earned 250 total points
ID: 12079263
And, if you're using "hungarian" notation where intDivision and intSponsor are both numeric, you won't need the single quote delimiters.  So you would have:

          SQLString = "upSponsorReportByDivision " & intDivision & ", " & intSponsor
0
 
LVL 2

Expert Comment

by:fcco
ID: 12083649
 SQLString = "EXEC upSponsorReportByDivision " & intDivision & ", " & intSponsor
0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12084196
Doh!  Of course.  : )
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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.

809 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