On Time code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Don't know where OnTime comes into it, but the test can be

ans = Inputbox("Inut number")
If ans <> 23 Then End

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
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
 
Robin,

Many thanks. This works. I was just wondering if there is something similar
for dates. e.g if you want it to time out after say 5 days?

Kind Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top