Monday, September 26, 2011

Read from Non-Notes Databases

Where : Populate Agent

Option Public
Uselsx "*lsxodbc"
Sub Initialize
      '-- Make ODBC Connection
     Dim Con As New ODBCConnection
     RetCode% = Con.ConnectTo("MRP System")
     '-- Define ODBC Query
     Dim Qry As New ODBCQuery
     '-- Set Connection property of ODBCQuery Object
     Set Qry.Connection = Con
     '-- Set SQL property of ODBCQueryObject
     '-- Set Query property of ODBCResultSet
     Dim res As New ODBCResultSet
     Set Res.Query = Qry
     '-- Execute the ODBC Query
     '-- Drill down to current database object
     Dim Session As New NotesSession
     Dim db As NotesDatabase
     Set db = Session.currentdatabase
     '-- Get First Row in ResultSet
     RetCode% = Res.FirstRow   
      '-- Iterate through result set creating a new document for each row     
     Do While RetCode% = True
          '-- Create new notes document object
          Dim Doc As New NotesDocument(db)         
          '-- Set form item
          doc.form = "Bikepart"
           '-- Populate document object with values from row
          doc.recid = Cstr( Res.GetValue("RECID") )
          doc.partno = Res.GetValue("PARTNO")
          doc.vendor = Res.GetValue("VENDOR")
          doc.type = Res.GetValue("TYPE")
          doc.dimension = Res.GetValue("DIMENSION")
          doc.cost = Res.GetValue("COST")
          '-- Save document
          Call (True, True)
          '-- Get Next Row in ResultSet
          RetCode% = Res.NextRow
     RetCode% = Res.Close( DB_CLOSE )
     RetCode% = Con.Disconnect    
End Sub

No comments:

Post a Comment