Last active
June 29, 2019 21:25
-
-
Save mbiette/a9d64b61f61451403d3c to your computer and use it in GitHub Desktop.
Connect to an AS/400 (iSeries) using ADODB in VBA.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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