Hi p45cal,
Thank you for replying.
I tried to record me changing the command text and it made following code:
Code:
Sub Change_Command_text()
'
' Change_Command_text Macro
'
'
With ActiveWorkbook.Connections("Query from AS400").ODBCConnection
.BackgroundQuery = True
.CommandText = Array( _
"SELECT REGNSKAB11.ACCGROUP, REGNSKAB11.ACCOUNT, REGNSKAB11.NAME, REGNSKAB11.COSTCENTER, REGNSKAB11.ACCYEAR, REGNSKA" _
, _
"B11.OBJECTIVE1, REGNSKAB11.OPENBABAS, REGNSKAB11.JANUAR, REGNSKAB11.FEBRUAR, REGNSKAB11.MARTS, REGNSKAB11.APRIL, RE" _
, _
"GNSKAB11.MAJ, REGNSKAB11.JUNI, REGNSKAB11.JULI, REGNSKAB11.AUGUST, REGNSKAB11.SEPTEMBER, REGNSKAB11.OKTOBER, REGNSK" _
, _
"AB11.NOVEMBER, REGNSKAB11.DECEMBER, REGNSKAB11.JAN2016, REGNSKAB11.FEB2016, REGNSKAB11.MAR2016, REGNSKAB11.ACCTYPE" & Chr(13) & "" _
, "" & Chr(10) & "FROM DKMAHE01.SGLQDATFIN.REGNSKAB11 REGNSKAB11")
.CommandType = xlCmdSql
.Connection = "ODBC;DSN=AS400;"
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Query from AS400")
.Name = "Query from AS400"
.Description = ""
End With
ActiveWorkbook.Connections("Query from AS400").Refresh
Range("A1").Select
End Sub
In the "Command text section" I changed it manually to REGNSKAB11 from REGNSKAB16. But I would like if the code could extract from a specific cell or something like that, so no matter if it says REGNSKAB11,
REGNSKAB16 or REGNSKAB34 in the specific cell, it would insert the specific string as above.
Additionally I could have a cell that had the entire Command text, that had dynamic numbers in the end of every "REGNSKAB" that the VBA code could use as reference.
i am just brainstorming, surely you'll have a great solution.
I cannot attach the Excel fil unfortunately.
I look forward to hear from you.
- Simon.
Bookmarks