Question : MS Access AS400 Function Understanding

I'm trying to create a function that would connect to AS400 and append a table to my access database.  I found a code and have been playing with it, but I can't get it work the way it should. Need some assistance.

Public Function Collect_AS400_Data()
Dim Cnxn As ADODB.Connection
Dim RS1 As ADODB.Recordset
Dim RS2 As ADODB.Recordset
Dim DB As Database
Dim strSQL As String

strSQL = "tblAS400"

Set DB = CurrentDb()

' Open connection
Set Cnxn = New ADODB.Connection
Cnxn.Open "Driver={Client Access ODBC Driver (32-bit)};System=REN-400;Uid=JBAKER;Pwd=password"

Set RS2 = new.ADODB.Recordset
Set RS1 = DB.OpenRecordset("strSQL")         ' Open Recordset.

RS2.Open "SSCPGM_ARPMPRCA", Cnxn, adOpenKeyset, adLockOptimistic, adCmdTable

RS2.MoveFirst
'Do while not RS2.EOF
RS1.AddNew

    RS1("PRCD") = RS2("PRCD")
    RS1("PRCDS") = RS2("PRCDS")
    RS1("TRLMG") = RS2("TRLMG")
    'Etc...

RS1.Update

RS1.Update

'RS2.MoveNext
'Loop

RS2.Close
Set RS2 = Nothing

RS1.Close
Set RS1 = Nothing

Cnxn.Close
Set Cnxn = Nothing

DB.Close
Set DB = Nothing

End Function

Answer : MS Access AS400 Function Understanding

see this link to connect to As400

http://www.carlprothman.net/Default.aspx?tabid=90#ODBCDriverForAS400
Random Solutions  
 
programming4us programming4us