Results 1 to 4 of 4
  1. #1
    Suttoa is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    7

    run a stored procedure on an IBM DB2

    Hey guys,



    So I am not very familiar with access VBA connection strings, or stored procedures on an IBM DB2 database. But from Access VBA I need to run a stored procedure on the IBM DB2.

    Currently my ODBC driver connects me to the IBM DB2 mainframe with a saved uid/pw.. the vb code creates the string formatted in the way it needs to be sent is ok. But trying to run the stored procedure has me ramming my head into the wall..

    Code for stored procedure:

    Code:
    Public Sub DB2SP_GS02NRSN_Command(strCriteria As String)
    '   Used for DB2 Stored Procedure calls
        Dim DB2SPcon As ADODB.Connection
        Dim DB2SPcmd As ADODB.Command
        Dim DB2SPRS As ADODB.Recordset
        Dim DB2SPparm As ADODB.Parameter
        
        Dim DB2SPenv As ADODB.Connection
        Set DB2SPcmd = New ADODB.Command
        
        '---  Replace below highlighted names with the corresponding values, then open it - not used:
             'DB2SPcon = "Driver={IBM DB2 ODBC DRIVER};DSN=GOLDTEST;DBALIAS=alias;"
             'DB2SPcmd.Open ("DB2SPcon")
    
    
        Set DB2SPcmd = New ADODB.Command
        Set DB2SPcmd.ActiveConnection = "TEST"
        DB2SPcmd.CommandType = adCmdStoredProc
        DB2SPcmd.CommandText = "GOLDTEST.GS02NRSN"
    '   Parameter list corresponds to Stored Procedure"s Linkage Section.
    '   various error checking functions here
    
    
        Set DB2SPRS = DB2SPcmd.Execute
    Right now when i try to run this I get a "compile error: Object Required" on the "TEST" name highlighted in red...
    I thought maybe I need to establish a connection to the odbc driver (called GOLDTEST) highlighted in Green.. but then I get a "Compile error: Method or data member not found" on DB2SPCon

    any help or thoughts on this would be nice.. I was reading about possibly using a "pass through query", but there are various error checking variables that need get filled in when this stored procedure is run.. so it sort of overcomplicated it..
    I guess I just want to know if I am connecting properly..

    Thank you!

  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
    ADO is not a strength, but I don't think you use Set for that line. Here's a snip from a working app:

    Code:
        Set cmd = New ADODB.Command
        With cmd
          .ActiveConnection = objConn
          .CommandText = "procResAddNew" 
          .CommandType = adCmdStoredProc
          ...
    In my case objConn is a connection object set in a separate procedure:

    Code:
      Set objConn = New ADODB.Connection
      objConn.ConnectionString = dbConnectionString
      objConn.CommandTimeout = 5
      objConn.Open
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Suttoa is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    7
    Thank you, that worked for me!

  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
    Happy to help!
    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. write stored procedure with 'if else'
    By shital in forum Access
    Replies: 9
    Last Post: 04-11-2018, 11:47 AM
  2. Help with SQL stored procedure
    By emmahope206 in forum Access
    Replies: 1
    Last Post: 05-24-2016, 05:03 PM
  3. Replies: 33
    Last Post: 09-25-2015, 08:39 AM
  4. Stored Procedure in MS Access 2007
    By sels1987 in forum Access
    Replies: 1
    Last Post: 05-13-2012, 12:23 PM
  5. Replies: 0
    Last Post: 05-12-2010, 09:41 AM

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