Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two forms with one click 2

Status
Not open for further replies.

krinid

Programmer
Jun 10, 2003
356
CA
Got these two forms which I bring up one at a time. The forms have a single listbox where the users picks an item, which I catch in listbox_Click, then unload the first form and bring up the second form with the next question.

Problem:
When the first form closes and the second form comes up, the mouse button is still clicked and causes the listbox_Click event on the second form to fire. It happens so fast the user may not even notice a form popped up, that they 'clicked' an option and the form unloaded.

Any good ideas to get around this?

Currently, I've done away with _Click and am using _DblClick and it's working fine, but I'd like to use _Click if I can get around this issue. I considered moving the locations of the forms as well so they don't overlap, but of course the best option is to have them come up in the center of the screen (like all other pop-up windows).
 
Even if the click event is still on, if the click event on form1 fires the Show event to load form2, why would a specific control (the other listbox) on form2 fire its click event? I would have thought that the Show event simply fires the Initialize event for the second form. Is there code there that would fire the second click?

Maybe change the first listbox firing to Update?

Gerry
 
For the problem above, I'm only using a single click. However, the listbox_Click event fires even when the mouse button is pressed elsewhere (ie: not on the listbox itself), held down and dragged onto the listbox. So when the second form pops up, the mouse pointer is atop one of the options in the listbox in the second form and the mouse button is down. (It's possible to click the mouse button and let go VERY QUICKLY and avoid the second window from firing its listbox_Click event, but I can't realstically expect users to do that.)
 
Why do you use two forms in the first place? Can't you have both controls (questions) on one form with an OK-button on it?

Have a nice day

Christer
 
The form itself is a generic user selection form - call the form, indicate what data to fill it with, and it provides the calling sub with the user's selection. The form is called whenever user input is required, and in this case, twice in a row.
 
OK - thanks for enlighten me. Sorry, but have no further ideas how to solve your problem.

But still - have a nice day (in spite of all....)

Christer
 
HaHa, thanks, you have a nice day, too. I'll most likely just stick with the double click method.
 
I think from your description, the only viable alternative to dbl click would be an ok button so that the user selects an option and has to move away from the listbox to ok it...seems like the double click would work better / be easier tho...

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
First off. It really does sound like there should be a command button to fire the events.

Pardon me for being dense, but I still do not understand. The second form, if it is a real second form, has to be called by a .Show.

In addition, if, as you wrote, the user can click elsewhere and drag it over the listbox, and it still fires into the second form...could you tell me how (or even why) you would have a list at all, if, as it sounds like, you can not properly select from that list? What if they click and drag over but hit an unintended item? The mouse is over list item #2, rather than list item #4 which is what they wanted. (This is just an example.)

I guess I really am dense, because it seems to me, that it should be a listbox, and a commandbutton. Or at least a listbox that fires on a Change event, or the Update event.

Gerry
 
Gerry - I believe the general issue is that the click (or dbl click) event of the listbox on form1 hides the 1st form but in doing so the focus is passed to the 2nd form and because the mouse button is still pressed, the click event of the 2nd form is fired also

Krinid - one way of doing it might be to build in a 1 second delay using the WAIT method:

Pseudocode:

Listbox1_Click()
Application.Wait(Now + TimeValue("0:00:01"))
Form1.hide
'Process data
end sub

this should give enough time for the mouse button to finish clicking before the 1st form is hidden and so shouldn't fire the click event of the listbox on the 2nd form

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
Help me out here. I am really trying to get it.

but in doing so the focus is passed to the 2nd form and because the mouse button is still pressed, the click event of the 2nd form is fired also

I can understand the focus being passed to the second form , but why is it being passed to a control on that form? I would have thought if a Click event is persistent, then the click persistence would be, as you state, passed with the focus to the second form. The second form itself, which has a click event. Or are you ststing that click persistence not only fires the second forms Click event, but a listbox control as well? If so, again, why would two[/] separate events happen? The Form2_Click, PLUS Listbox2_Click.

This is, I assume, only applicable if Listbox2 is TabIndex = 0. Because if it is not, then I am even more confused. How would a listbox control_click fire automaticlly. It is the form (not the listbox), that is receiving focus. It is the form (not the listbox) that gets the persistence of the mouse click.

I guess I am being dense, hey I just found out that when form_initialize completes, TabIndex 0_Click fires automati..........never mind. I get it now.

So change the listbox on Form2 to TabIndex <> 0?

Gerry
 
I'm guessing the listboxes are in the same position on the screen so that when the 1st is clicked, the event fires and hides the form. Before the user releases the mouse button, the next form is popped up with the listbox already "under" the mouse pointer. When the mouse button is released, this then fires off the listobx2 click event....at least, that is how I am understanding the issue

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
That's right, Geoff. The 2nd listbox appears in exactly the same spot as the previous one (it's in fact a different instance of the same form filled with different data).

The order of events is:
- form 1 pops up with listbox 1
- user clicks item A in listbox 1 BUT is still holding down the mouse button
- listbox1_click event fires
- form 1 unloads
- form 2 pops up with listbox 2 in exactly the same position as listbox 1 - thus the mouse pointer is overtop listbox 2 now
- as user is still holding down the mouse button, the listbox2_click event fires

The time between clicking on listbox1 and the subsequent firing of listbox2_click event is smaller than the average duration of a typical mouse button click.

Geoff, Gerry,
Thanks for the responses - I'm going to go with the command button and double click methods (give the user his choice of either one).

Btw, Gerry - what's the meaning of your ID? (I ask b/c it means 'unknown' in Japanese; I've been wondering for a while if that was the intended meaning or not).
 
Is there no MouseUp event ?

If there is, then just...

private sub My_Main_Form_Event()
frmOne.Show
frmTwo.Show
end sub

private sub frmOne.listbox_MouseUp(stuff here)
frmTwo.MyObj.text = frmOne.listbox.list()
unload me
end sub

Else
ignore post
end if

I'm unsure of the correct syntax for all this, but I think my theory is correct.

DarkMain
 
Not sure I understand what you're getting at - what role does the MouseUp event play?
 
I believe it also has some reference to an ornamental tree in Japan, the Japanese apricot, Prunus mume.

If you know it means unknown in Japanese, could you tell me why an Japanese automobile web page states that the frame is "fumei"? How can a Toyota have an unknown frame?

It is also a family name in Italy.

It means "bitter taste" in Cantonese.

It is also a first name among some Vietnamese.

You are the first to catch it. I'd give you a star, but it seems out of context.

Gerry
 
Actually DarkMain has a point, and I believe you could make it work using those events, but really...why make it more complex than you have to? Use a commandbutton. Or use a multi-page on one form, instead of using different forms.

Gerry
 
Gerry,
I'm interested in testing our DarkMain's point (if for nothing else than for the fun of it and to learn something from it) but I don't see what role the MouseUp event has... MouseUp means 'moving the mouse pointer up' doesn't it? (Or is it the mouse button up? In that case, it'd be great!)

Btw, yes, a star would be a bit out of context, but thanks for the thought! :) I didn't realize it was such a multicultural user ID. I particularly like bitter taste in Cantonese. As for the unknown Toyota frame - you got me! (Are we talking car frames or web page frames here?)
 
Actually, it is the name of my cat who is grey and I didn't want to name him "Smoke", or "Grey", or "Fume".

Anyway, I think you could do some playing around with the Mouse events, but again, why bother? Personally, I do not think using the ListBox_Click event is a good programming practice anyway. The event is for the Listbox, when (in most cases) what is really wanted is action regarding an item in that Listbox. Not the listbox itself. What if the user clicks an item, but they intended the one above it, or below? The Click event will still fire, because you are not really clicking an item, you are clicking the box itself.

Which means more potential error trapping. Did they really mean to click the box? Dd they really mean that particular item? Easier to use a commandbutton.

There certainly are uses for the Listbox_Click event, but I don't use it to get data out of the box. I use it to to validate and repopulate the items.

Gerry
 
MouseDown occurs when the user presses the mouse button; MouseUp occurs when the user releases the mouse button.

If a mouse button is pressed while the pointer is over a form or control, that object "captures" the mouse and receives all mouse events up to and including the last MouseUp event.

The order is:

MouseDown
MouseUp
Click
DblClick
MouseUp

Notice that the MouseDown AND Up events fire before the Click event. So, yes, you could use code in the the MouseUp to do something.


Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top