Thread: On Time code
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
external usenet poster
 
Posts: 575
Default On Time code

Kevin,

If you are using a standard input box I don't think so. You can create a
custom form and show it as a modeless form in XL2000 or higher, then have an
OnTime command check whether the value has been entered by a certain time.
OnTime is not that reliable however and this could easily mess up. So, I've
illustrated a better technique using a timer control:

'Put this in a general Module
'first technique using OnTime, which is easily messed up
'by clicking in the formula bar
'create a userform called frmPassword and add a text box called txtInput

Option Explicit
Option Private Module

Public dtTimeOut As Date 'used by second technique

Sub UnReliableTestForPassword()
frmPassword.Show vbModeless
Application.OnTime Now + TimeSerial(0, 0, 20), "CheckPassword"
End Sub

Sub CheckPassword()
Dim strCheck As String
strCheck = frmPassword.txtInput.Text
Unload frmPassword
If strCheck < "abc" Then
MsgBox "You password was not entered correctly", vbOKOnly, "Timed Out"
End
Else
MsgBox "System access granted", vbOKOnly, "Validation confirmed"
'run other macro to launch system here
End If
End Sub

'second technique using my VBA Timer control which is less easily
circumvented
'add the timer control from
'http://www.enhanceddatasystems.com/ED/Pages/ExcelTimer.htm
'to frmPassword

Sub MoreReliableTestForPassword()
dtTimeOut = Now + TimeSerial(0, 0, 20)
frmPassword.Show vbModeless
With frmPassword.Timer1
.Interval = 1000
.Enabled = True
End With
End Sub

'and put this in frmPassword's code section
Private Sub Timer1_Timer()
Dim strCheck As String
If Now dtTimeOut Then
Timer1.Enabled = False
strCheck = frmPassword.txtInput.Text
If strCheck < "abc" Then
MsgBox "You password was not entered correctly", vbOKOnly, "Timed
Out"
End
Else
MsgBox "System access granted", vbOKOnly, "Validation confirmed"
'run other macro to launch system here
End If
Unload Me
End If
End Sub

Robin Hammond
www.enhanceddatasystems.com

"kevin" wrote in message
...
Is there anyway of using the OnTime command which when reached will exit
the
program unless a specific number is inserted into a input box.

Can you advise f the code?

Many thanks.

Kevin.