#1   Report Post  
Posted to microsoft.public.excel.misc
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



  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,726
Default input box

Dim queryDate As Date
Application.ScreenUpdating = False
Sheets("NSKData").Select
With Range(Range("A1:E1"), Range("A1:E1").End(xlDown))
.ClearContents
.QueryTable.Delete
End With
On Error Resume Next
queryDate = InputBox("Enter a Date")
If Err.Number = 0 Then
With ActiveSheet.QueryTables.Add( _
Connection:=Array(Array( _
"ODBC;DSN=trop;UID=MAYNEM;PWD=trader;DBQ=TROP.WORL D;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB= T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;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
End If
Sheets("ChartNSK").Select
Application.ScreenUpdating = True


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"MikeM" wrote in message
...
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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Prevent Duplicate Data from inputing using input application? Zigball Excel Worksheet Functions 8 October 16th 06 11:01 PM
How to Prevent Duplicate Data from inputing using input application? Zigball Excel Discussion (Misc queries) 1 October 10th 06 05:56 PM
How to Prevent Duplicate Data from inputing using input application? Zigball New Users to Excel 1 October 10th 06 05:31 PM
input box Monty Excel Discussion (Misc queries) 2 October 7th 05 08:33 AM
Input Form vba help mdalzell Excel Discussion (Misc queries) 0 April 8th 05 03:57 PM


All times are GMT +1. The time now is 11:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"