Code that does work:
Sub Automation()
Dim strPass As String
Dim strUID As String
UserForm1.Show
strUID = UserName
strPass = Password
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=Prodbank;Pwd=" & strPass & ";DB=repository;UID=" & strUID & ";", Destination:=Sheets("sheet1").Range("A24"))
.CommandText = Array( _
"SELECT pdp_swap_dv01.val_name, pdp_swap_dv01.amount, pdp_swap_dv01.npv_0, pdp_swap_dv01.dv01, pdp_swap_dv01.prod_date" & Chr(13) & "" & Chr(10) & "FROM repository.dbo.pdp_swap_dv01 pdp_swap_dv01" & Chr(13) & "" & Chr(10) & "WHERE (pdp_swap_dv01.prod_date={" _
, "ts '2009-11-30 00:00:00'})")
.Name = "DV_02"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
Code that does not work:
Sub Automation()
Dim strPass As String
Dim strUID As String
Dim strEOM As String
UserForm1.Show
strUID = UserName
strPass = Password
strEOM = EOM
strEOM = Format(Date, "yyyy-mm-dd h:mm")
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=Prodbank;Pwd=" & strPass & ";DB=repository;UID=" & strUID & ";", Destination:=Sheets("sheet1").Range("A24"))
.CommandText = Array( _
"SELECT pdp_swap_dv01.val_name, pdp_swap_dv01.amount, pdp_swap_dv01.npv_0, pdp_swap_dv01.dv01, pdp_swap_dv01.prod_date" & Chr(13) & "" & Chr(10) & "FROM repository.dbo.pdp_swap_dv01 pdp_swap_dv01" & Chr(13) & "" & Chr(10) & "WHERE (pdp_swap_dv01.prod_date=(" & strEOM & ")")
.Name = "DV_02"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
|