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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsgBox keeps switching forms

Status
Not open for further replies.

StuH

Programmer
Mar 25, 2001
53
0
0
AU
I have two forms, form1 and form2. form2 is on top of form1. I click a button on form2 which firstly displays a MsgBox with Yes/No option to continue.

Problem is, when I click the button, form1 jumps on top of form2, then the message box is displayed. When I click either button on the MsgBox, it disappears (as expected) and form2 jumps back on to of form1.

It's as if the MsgBox is somehow tied to form1. There is no code to show/hide any form, just seems to be doing it by itself.

Any suggestions?
 
But.. there is some code to display the messagebox? What that code is doing? can you show us?

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
It was just a simple message box of type 4 with Yes/No buttons.

I got fed up and decided to make my own form to use as a message box. It worked perfectly.
 
I have seen that happen before and could not find any reason to explain it, i think i used the same solution and made my own msgbox to solve it also. would be nice to know what caused it.
 
Hi BobRhodes,

If I start an app from scratch and make the two forms and produce the MsgBox, it behaves as it should. But I think in this case, I have an app with 18 forms and it's just gone crazy. I did a search of past problems with MsgBox here and found another where a guy described the exact same problem with no solution offered other than build your own message form - so I did as azrobert did.

Very frustrating, but there is that workaround.

Thanks,

Stu.
 
It could be a number of things!. Is there a change event firing when the msgbox is closed?. There must be some code in there to unload the form.
What about opening the second form Modaly

dim frm as new frmForm1
frm.Show , vbModal

Without seeing the code hard to tell!.
 
Ok. I've never run across the problem, but you might take your form and show it modally if you didn't already, and see if that recreates the problem. Then you'll know it has something to do with modality.

Bob
 
Here is one option that you could use. On form1 do the following:

Private Sub Form_Load()
Form2.Show 'Opens Form 2
End Sub

Private Sub Form_LostFocus()
If Not blnFormMove Then
Form1.SetFocus 'Keep focus on current form
If MsgBox("Do you want to go to the other form?", vbYesNo, "Go To Form 2") = vbYes Then
blnFormMove = True ' Toggles Variable so code will not execute again (otherwise it will be an unending loop).
Form2.SetFocus
End If
End If
End Sub

On form2:

Private Sub Form_LostFocus()
blnFormMove = False
End Sub

Note: blnFormMove needs to be declared as a global variable.
 
Just a thought.

What service pack is installed?

Service pack 6 is available and has been for quite some time. I would install service pack 6 if you do not already have it installed

 
Denster: I need the form to not be modal so it's not an option for me.

Thanks ComputerDude, I'll give it a try because I can still generate the problem even though I've done a workaround.

Thendrickson: yes I have SP6.

Stu.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top