Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with passing 2 variables to Stored Procedure

Posted on 2004-09-16
4
Medium Priority
?
268 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 1000 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

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.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 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