Thread: input box
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
MikeM MikeM is offline
external usenet poster
 
Posts: 64
Default input box

Hello folks,

I have the folowing vb script which I have managed to cobble together and it
works very well. Except that is if the user cancels instead of entering a
date at which point it errors. I would really like it if the user cancels
then that would cancel the macro.


Help.

Thanks,

Mike

Dim queryDate As Date
Application.ScreenUpdating = False
Sheets("NSKData").Select
Range("A1").Select
Range("A1:E1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Selection.QueryTable.Delete
'Range("G1").Select
'queryDate = Range("G1")
queryDate = InputBox("Enter a Date")
With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DSN=trop;UID=MAYNEM
;PWD=trader;DBQ=TROP.WORLD;DBA=W;APA=T;EXC=F;FEN=T ;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=I fAllSuccessful;MTS=" _
), Array("F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;")),
Destination:=Range("A1"))
.CommandText = Array( _
"select trading_date, period, sum(band1_6sec_max)
,sum(band1_60sec_max)from tr_owner.tr_pcmp_offer_summ where status = 'c' and
asset_owner_code = 'SKOG'and trading_date = '" & queryDate & "' group by
trading_date, period order " _
, "by 1, 2")
.Name = "Query from trop"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Sheets("ChartNSK").Select
Application.ScreenUpdating = True
End Sub