Hello: Alias is OK
Example of VBA Code used.
Sub Update_ConnectionName()
Dim NomeArray As String
Dim Shieldname As String
‘On Error Resume Next
Activeshield = ActiveWindow.Caption
Shieldname = ActiveCell.Worksheet.Name
‘ Create DDM file on AS400
NomeArray = “CREATE ALIAS SQLEXCEL.Namefile FOR Libname.Namefile (MbrName)”
With ActiveWorkbook.Connections(“ConnectionName”).ODBCConnection
.BackgroundQuery = False
.CommandText = NomeArray
.CommandType = xlCmdSql
.Connection = Array(Array( _
“ODBC;DRIVER={iSeries Access ODBC Driver};ODBC;” & Chr(13) & “” & Chr(10) & “DSN=Dsnname.dsn;BLOCKSIZE=1024;QRYSTGLMT=-1” _
), Array( _
“;PKG=QGPL/DEFAULT(IBM),2,0,1,0,512;LANGUAGEID=ENU;DFTPKGLIB=QGPL;DBQ=Libname Libname;SYSTEM=192.168.123.14;” _
))
.RefreshOnFileOpen = False
.SavePassword = True
.SourceConnectionFile = “”
.SourceDataFile = “”
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
Application.DisplayAlerts = False
ActiveWorkbook.Connections(“ConnectionName”).Refresh
Application.DisplayAlerts = True
‘ Run Query on DDM file
NomeArray = “SELECT * FROM EXCELTEMP.namefile
With ActiveWorkbook.Connections(“ConnectionName”).ODBCConnection
.BackgroundQuery = False
.CommandText = NomeArray
.CommandType = xlCmdSql
.Connection = Array(Array( _
“ODBC;DRIVER={iSeries Access ODBC Driver};ODBC;” & Chr(13) & “” & Chr(10) & “DSN=Dsnname.dsn;BLOCKSIZE=1024;QRYSTGLMT=-1” _
), Array( _
“;PKG=QGPL/DEFAULT(IBM),2,0,1,0,512;LANGUAGEID=ENU;DFTPKGLIB=QGPL;DBQ=Libname Libname;SYSTEM=192.168.123.14;” _
))
.RefreshOnFileOpen = False
.SavePassword = True
.SourceConnectionFile = “”
.SourceDataFile = “”
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
ActiveWorkbook.Connections(“ConnectionName”).Refresh
‘ Delete DDM file on As400
‘NomeArray = “DROP ALIAS SQLEXCEL.Namefile”
With ActiveWorkbook.Connections(“ConnectionName”).ODBCConnection
.BackgroundQuery = False
.CommandText = NomeArray
.CommandType = xlCmdSql
.Connection = Array(Array( _
“ODBC;DRIVER={iSeries Access ODBC Driver};ODBC;” & Chr(13) & “” & Chr(10) & “DSN=Dsnname.dsn;BLOCKSIZE=1024;QRYSTGLMT=-1” _
), Array( _
“;PKG=QGPL/DEFAULT(IBM),2,0,1,0,512;LANGUAGEID=ENU;DFTPKGLIB=QGPL;DBQ=Libname Libname;SYSTEM=192.168.123.14;” _
))
.RefreshOnFileOpen = False
.SavePassword = True
.SourceConnectionFile = “”
.SourceDataFile = “”
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
Application.DisplayAlerts = False
ActiveWorkbook.Connections(“ConnectionName”).Refresh
Application.DisplayAlerts = True
End Sub
Discuss This Question: 12  Replies