Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Close automatically a userform

How to close a userform if no entry is made within 10 seconds? Kindly help
with an appropriate macro.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Close automatically a userform

Code goes into the user form's code section, not the workbook itself. For
the examples, the user form's name is UserForm1

1st method: if no entry made for 10 seconds, form closes, but any entry made
causes it to remain open no matter how long it takes to finish entries.

Option Explicit
Public myUserFormFlag As Boolean

Private Sub UserForm_Activate()
Dim startTimer As Long
myUserFormFlag = False
startTimer = Timer
Do While myUserFormFlag = False
DoEvents
If Timer (startTimer + 10) Then
UserForm1.Hide
Exit Do
End If
Loop
End Sub

Private Sub ComboBox1_Change()
myUserFormFlag = True
End Sub

Private Sub TextBox1_Change()
myUserFormFlag = True
End Sub

The 'secret' in that is that you need to add the line
myUserFormFlag = True
at the start of any action event for any of your controls on the form. Then
when any one of them is used, the timing tests stop and the form stays open.

A second method: this one will keep the form open as long as someone does
something, as type a letter into a text box, at least once each 10 seconds,
but once no action has taken place on the form at all for 10 seconds, it
closes, even with partially completed text entries:

Option Explicit
Public startTimer As Long

Private Sub UserForm_Activate()
startTimer = Timer
Do While Timer < (startTimer + 10)
DoEvents
Loop
UserForm1.Hide
End Sub

Private Sub ComboBox1_Change()
startTimer = Timer
End Sub

Private Sub TextBox1_Change()
startTimer = Timer
End Sub

With this second one, the 'secret' is in resetting startTimer when any
control is changed/used on the form. So the 10-second clock gets restarted
any time there is activity on the form.

I showed how to do it with a form with a ComboBox and a TextBox on it, just
do much the same for any/all controls on the form and you should be fine.

"FARAZ QURESHI" wrote:

How to close a userform if no entry is made within 10 seconds? Kindly help
with an appropriate macro.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Close automatically a userform

Thanx bro
Shall try out the same.
Can u help me out one another problem?
I want a timestamp to be appearing for each and every entry in column A in
corresponding column B. The problem is that whether the entry is made as
punched/typed or pased. In other words if I paste an array/range in a single
Ctrl+V or Enter stroke, on cells A1:A10 I want the cells B1:B10 to be
reflecting a time stamp on every cell.

"JLatham" wrote:

Code goes into the user form's code section, not the workbook itself. For
the examples, the user form's name is UserForm1

1st method: if no entry made for 10 seconds, form closes, but any entry made
causes it to remain open no matter how long it takes to finish entries.

Option Explicit
Public myUserFormFlag As Boolean

Private Sub UserForm_Activate()
Dim startTimer As Long
myUserFormFlag = False
startTimer = Timer
Do While myUserFormFlag = False
DoEvents
If Timer (startTimer + 10) Then
UserForm1.Hide
Exit Do
End If
Loop
End Sub

Private Sub ComboBox1_Change()
myUserFormFlag = True
End Sub

Private Sub TextBox1_Change()
myUserFormFlag = True
End Sub

The 'secret' in that is that you need to add the line
myUserFormFlag = True
at the start of any action event for any of your controls on the form. Then
when any one of them is used, the timing tests stop and the form stays open.

A second method: this one will keep the form open as long as someone does
something, as type a letter into a text box, at least once each 10 seconds,
but once no action has taken place on the form at all for 10 seconds, it
closes, even with partially completed text entries:

Option Explicit
Public startTimer As Long

Private Sub UserForm_Activate()
startTimer = Timer
Do While Timer < (startTimer + 10)
DoEvents
Loop
UserForm1.Hide
End Sub

Private Sub ComboBox1_Change()
startTimer = Timer
End Sub

Private Sub TextBox1_Change()
startTimer = Timer
End Sub

With this second one, the 'secret' is in resetting startTimer when any
control is changed/used on the form. So the 10-second clock gets restarted
any time there is activity on the form.

I showed how to do it with a form with a ComboBox and a TextBox on it, just
do much the same for any/all controls on the form and you should be fine.

"FARAZ QURESHI" wrote:

How to close a userform if no entry is made within 10 seconds? Kindly help
with an appropriate macro.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Close automatically a userform

I believe Gord Dibben is trying to assist you with that in another
discussion. Best to just continue that discussion there rather than mixing
things up and continuing here. I will look at that and if I can add to the
discussion, I will.

"FARAZ QURESHI" wrote:

Thanx bro
Shall try out the same.
Can u help me out one another problem?
I want a timestamp to be appearing for each and every entry in column A in
corresponding column B. The problem is that whether the entry is made as
punched/typed or pased. In other words if I paste an array/range in a single
Ctrl+V or Enter stroke, on cells A1:A10 I want the cells B1:B10 to be
reflecting a time stamp on every cell.

"JLatham" wrote:

Code goes into the user form's code section, not the workbook itself. For
the examples, the user form's name is UserForm1

1st method: if no entry made for 10 seconds, form closes, but any entry made
causes it to remain open no matter how long it takes to finish entries.

Option Explicit
Public myUserFormFlag As Boolean

Private Sub UserForm_Activate()
Dim startTimer As Long
myUserFormFlag = False
startTimer = Timer
Do While myUserFormFlag = False
DoEvents
If Timer (startTimer + 10) Then
UserForm1.Hide
Exit Do
End If
Loop
End Sub

Private Sub ComboBox1_Change()
myUserFormFlag = True
End Sub

Private Sub TextBox1_Change()
myUserFormFlag = True
End Sub

The 'secret' in that is that you need to add the line
myUserFormFlag = True
at the start of any action event for any of your controls on the form. Then
when any one of them is used, the timing tests stop and the form stays open.

A second method: this one will keep the form open as long as someone does
something, as type a letter into a text box, at least once each 10 seconds,
but once no action has taken place on the form at all for 10 seconds, it
closes, even with partially completed text entries:

Option Explicit
Public startTimer As Long

Private Sub UserForm_Activate()
startTimer = Timer
Do While Timer < (startTimer + 10)
DoEvents
Loop
UserForm1.Hide
End Sub

Private Sub ComboBox1_Change()
startTimer = Timer
End Sub

Private Sub TextBox1_Change()
startTimer = Timer
End Sub

With this second one, the 'secret' is in resetting startTimer when any
control is changed/used on the form. So the 10-second clock gets restarted
any time there is activity on the form.

I showed how to do it with a form with a ComboBox and a TextBox on it, just
do much the same for any/all controls on the form and you should be fine.

"FARAZ QURESHI" wrote:

How to close a userform if no entry is made within 10 seconds? Kindly help
with an appropriate macro.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Close automatically a userform

Hi,

No doubt Gord was handling the matter quite great but has given up. You can
reply me in that question panel as well.

"JLatham" wrote:

I believe Gord Dibben is trying to assist you with that in another
discussion. Best to just continue that discussion there rather than mixing
things up and continuing here. I will look at that and if I can add to the
discussion, I will.

"FARAZ QURESHI" wrote:

Thanx bro
Shall try out the same.
Can u help me out one another problem?
I want a timestamp to be appearing for each and every entry in column A in
corresponding column B. The problem is that whether the entry is made as
punched/typed or pased. In other words if I paste an array/range in a single
Ctrl+V or Enter stroke, on cells A1:A10 I want the cells B1:B10 to be
reflecting a time stamp on every cell.

"JLatham" wrote:

Code goes into the user form's code section, not the workbook itself. For
the examples, the user form's name is UserForm1

1st method: if no entry made for 10 seconds, form closes, but any entry made
causes it to remain open no matter how long it takes to finish entries.

Option Explicit
Public myUserFormFlag As Boolean

Private Sub UserForm_Activate()
Dim startTimer As Long
myUserFormFlag = False
startTimer = Timer
Do While myUserFormFlag = False
DoEvents
If Timer (startTimer + 10) Then
UserForm1.Hide
Exit Do
End If
Loop
End Sub

Private Sub ComboBox1_Change()
myUserFormFlag = True
End Sub

Private Sub TextBox1_Change()
myUserFormFlag = True
End Sub

The 'secret' in that is that you need to add the line
myUserFormFlag = True
at the start of any action event for any of your controls on the form. Then
when any one of them is used, the timing tests stop and the form stays open.

A second method: this one will keep the form open as long as someone does
something, as type a letter into a text box, at least once each 10 seconds,
but once no action has taken place on the form at all for 10 seconds, it
closes, even with partially completed text entries:

Option Explicit
Public startTimer As Long

Private Sub UserForm_Activate()
startTimer = Timer
Do While Timer < (startTimer + 10)
DoEvents
Loop
UserForm1.Hide
End Sub

Private Sub ComboBox1_Change()
startTimer = Timer
End Sub

Private Sub TextBox1_Change()
startTimer = Timer
End Sub

With this second one, the 'secret' is in resetting startTimer when any
control is changed/used on the form. So the 10-second clock gets restarted
any time there is activity on the form.

I showed how to do it with a form with a ComboBox and a TextBox on it, just
do much the same for any/all controls on the form and you should be fine.

"FARAZ QURESHI" wrote:

How to close a userform if no entry is made within 10 seconds? Kindly help
with an appropriate macro.

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
default template (book.xlt) doesn't close Michael Excel Discussion (Misc queries) 3 December 2nd 05 05:13 PM
close button does not close goplayoutside Excel Discussion (Misc queries) 1 October 11th 05 03:42 PM
automatically close hyperlink with back button Holly Williams Excel Worksheet Functions 2 September 20th 05 02:10 PM
closing 1 file at a time Keith G Hicks Excel Discussion (Misc queries) 4 September 4th 05 02:16 AM
Excel shoud not close all active books when clicking close button technomike Excel Discussion (Misc queries) 0 June 10th 05 05:35 PM


All times are GMT +1. The time now is 03:33 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"