Solved

Help with passing 2 variables to Stored Procedure

Posted on 2004-09-16
4
264 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

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