Solved

Help with passing 2 variables to Stored Procedure

Posted on 2004-09-16
4
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 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