Skip to content

Instantly share code, notes, and snippets.

@mbiette
Last active June 29, 2019 21:25
Show Gist options
  • Save mbiette/a9d64b61f61451403d3c to your computer and use it in GitHub Desktop.
Save mbiette/a9d64b61f61451403d3c to your computer and use it in GitHub Desktop.
Connect to an AS/400 (iSeries) using ADODB in VBA.
Function GetFileContentFromAS400(host As String, iasp as String, library As String, filename As String) As String
Dim myConnect As New ADODB.Connection
Dim rsRecords As New ADODB.Recordset
Dim fileContent As String
With myConnect
If .State = adStateOpen Then
myConnect.Close
End If
.Open "Driver=iSeries Access ODBC Driver;SYSTEM=" + host + ";DATABASE=" + iasp + ";COMPRESSION=1;TRANSLATE=1;"
End With
rsRecords.Open "SELECT * FROM " + library + "." + filename + "", myConnect
fileContent = ""
Do Until rsRecords.EOF
If fileContent <> "" Then
fileContent = fileContent & vbLf & rsRecords(0).Value
Else
fileContent = rsRecords(0).Value
End If
rsRecords.MoveNext
Loop
rsRecords.Close
myConnect.Close
GetFileContentFromAS400 = fileContent
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment