Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Modeless form for user interaction

Suppose I want to use a form which prompts the user to
select a cell and press an OK buttom on the form when
ready. I figure the form must be modeless, but how do I
prevent the code following the statement
frmMyForm.Show
from executing until the OK button on the form has been
clicked?

TIA, Arne
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Modeless form for user interaction

One way to select a cell without having to reinvent the
wheel, via a modless form, is to use:

Dim myRange as Range
Set myRange = Application.InputBox( _
"Select a cell", Type:=8)


But if your form is used to do more than just pick a cell,
then to prevent code from executing until the OK button is
clicked, you can use a public boolean flag and a DoEvent
within a Do While loop.

In your module's declarations section at the top:
Public OKButtonClicked as Boolean

In the VBA routine that calls the form:

Private MySubroutine()
'some code
OKButtonClicked = False
frmMyForm.Show
Do While Not OKButtonClicked
DoEvents
Loop
'some more code
End Sub

And finally in your form's OK button:
Private Sub cmdOK_Click()
'Your Code
OKButtonClicked = True
End Sub


Or as an alternate to the boolean flag, I often hide the
form after the OK button is clicked, so I might use:

frmMyForm.Show
Do While frmMyForm.Visible
DoEvents
Loop
'More code here


-----Original Message-----
Suppose I want to use a form which prompts the user to
select a cell and press an OK buttom on the form when
ready. I figure the form must be modeless, but how do I
prevent the code following the statement
frmMyForm.Show
from executing until the OK button on the form has been
clicked?

TIA, Arne
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Modeless form for user interaction

Great, thanks for the information.

Arne
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Modeless form for user interaction

Do you really need the flag to check, if OK-button is
pressed.

If you create an user form and set the ShowModal property
False (if you don't have the Properties window, select it
from View menu), then you get this wanted functionality.
After that you just create OK-button and put Unload Me in
the end of the button's code.

In this case you can call the user form normally
(UserFrm.Show) and the code won't be executed until OK-
button is pressed.

Sub Test

UserFrm.Show 'waits until OK-button is pressed
Code continues...

End Sub

Or am I missing something here...

Ecco

-----Original Message-----
One way to select a cell without having to reinvent the
wheel, via a modless form, is to use:

Dim myRange as Range
Set myRange = Application.InputBox( _
"Select a cell", Type:=8)


But if your form is used to do more than just pick a

cell,
then to prevent code from executing until the OK button

is
clicked, you can use a public boolean flag and a DoEvent
within a Do While loop.

In your module's declarations section at the top:
Public OKButtonClicked as Boolean

In the VBA routine that calls the form:

Private MySubroutine()
'some code
OKButtonClicked = False
frmMyForm.Show
Do While Not OKButtonClicked
DoEvents
Loop
'some more code
End Sub

And finally in your form's OK button:
Private Sub cmdOK_Click()
'Your Code
OKButtonClicked = True
End Sub


Or as an alternate to the boolean flag, I often hide the
form after the OK button is clicked, so I might use:

frmMyForm.Show
Do While frmMyForm.Visible
DoEvents
Loop
'More code here


-----Original Message-----
Suppose I want to use a form which prompts the user to
select a cell and press an OK buttom on the form when
ready. I figure the form must be modeless, but how do I
prevent the code following the statement
frmMyForm.Show
from executing until the OK button on the form has been
clicked?

TIA, Arne
.

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Modeless form for user interaction

That does not work in Excel 2000. The code following the
show method call is executed right away.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Modeless form for user interaction

You're right. My memory didn't serve me right this time.
Thank you for your correction.

Ecco

-----Original Message-----
That does not work in Excel 2000. The code following the
show method call is executed right away.

.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Modeless form for user interaction

Ah, more useful advice.
Thanks a bundle.

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 Email does not need user interaction ? Koulla Excel Discussion (Misc queries) 4 October 15th 08 02:41 PM
How do I fill a cell in a user form from a selection on same form? Terry Tipsy Excel Discussion (Misc queries) 4 June 11th 07 02:59 PM
Interaction of form controls and pictures in Excel 2007 keithrmanning Excel Worksheet Functions 7 November 9th 06 03:39 PM
User form Mike Rogers Excel Discussion (Misc queries) 2 March 10th 06 05:56 PM
Modeless userform hngo New Users to Excel 2 July 13th 05 09:23 AM


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