Results 1 to 7 of 7
  1. #1
    allenjasonbrown@gmail.com is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44

    Return Procedure variable to VBA

    Hello -

    I am using the following code in Access. Can anyone tell me how to return that last output variable back to the VBA? The SP has 3 inputs and 1 output. I am just trying to get the one output and eventually put it on a form.

    ' Set oConn = New ADODB.Connection
    Set oCmd = New ADODB.Command
    oConn.ConnectionString = vDBConnectString
    oConn.Open
    oConn.CommandTimeout = 0
    Set oCmd.ActiveConnection = oConn
    oCmd.CommandTimeout = 0
    oCmd.CommandText = cProcName
    oCmd.CommandType = adCmdStoredProc
    oCmd.Parameters.Append oCmd.CreateParameter("RetVal", adVarChar, adParamReturnValue)
    oCmd.Parameters.Append oCmd.CreateParameter("pText1", adVarChar, adParamInput, 50)
    oCmd.Parameters.Append oCmd.CreateParameter("pCombo64", adVarChar, adParamInput, 50)
    oCmd.Parameters.Append oCmd.CreateParameter("pCombo66", adVarChar, adParamInput, 50)
    'oCmd.Parameters.Append oCmd.CreateParameter("@policy_number", adVarChar, adParamOutput, 50)


    oCmd
    ("pText1") = Text1
    oCmd("pCombo64") = Combo64
    oCmd("pCombo66") = Combo66

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    MsgBox oCmd.Parameters("@policy_number")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    allenjasonbrown@gmail.com is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    It is empty

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What does the SP look like? Did you execute the SP? I have a process that ends like this:

    Code:
    .Parameters.Append .CreateParameter("@RetResNum", adVarChar, adParamOutput, 15)
    
    .Execute
    
    strMsg = .Parameters("@RetResNum")
    
    MsgBox "Reservation Number: " & strMsg
    And it correctly returns the value from the SP to the user.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    allenjasonbrown@gmail.com is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    Hi -

    It is a basic stored procedure with a few inputs a 1 output. It works like a charm if I just run it from Query Analyzer. All the procedure does is perform an insert and an update. The update uses the output field which updates correctly so I know the field gets populated in the proc and also as I mentioned from query analyzer it works great. The procedure works from access and does the insert and update great.....it just looks like the ouput variable does not make it back to access.

  6. #6
    allenjasonbrown@gmail.com is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    Thanks for your help. I got it to work. I just had a typo.....uggh.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Excellent, glad you got it working.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 PM
  2. Passing variable values to Stored Procedure
    By rodrigopcnet in forum Access
    Replies: 1
    Last Post: 04-14-2010, 10:35 AM
  3. Replies: 1
    Last Post: 04-13-2010, 12:18 PM
  4. How to run VBA procedure
    By bkelly in forum Programming
    Replies: 8
    Last Post: 09-26-2009, 06:08 PM
  5. stored procedure return value to access form
    By rbw940 in forum Programming
    Replies: 0
    Last Post: 10-13-2008, 01:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums