Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

main form is shown undeliberately

Posted on 1998-04-29
15
311 Views
Last Modified: 2012-05-04
I have a VB form that calls a procedure from
another class to verify whether an input in
a textbox of that form is in the allowed range
of input values. Now if the focus is lost in that
textbox the Lost event handling procedure in the
form calls this other procedure from the mentioned
class. This procedure in turn calls MsgBox when the
input value range is violated  to inform the user.
However, before this message box comes up the main
form is shown and over this appears the message box.
When OK is clicked the main form disappears again.
Is there a way to suppress the main form showing up
each time the MsgBox is shown? It does not make any
sense to have the main form shown in this occasion.
0
Comment
Question by:quark031698
  • 7
  • 4
  • 2
  • +1
15 Comments
 
LVL 9

Expert Comment

by:Dalin
ID: 1433709
Quark,
There are problems related to use the LostFocus to validate input, and have a messageBox in the lost Focus event. Check out:
    PRB: GotFocus Event Fails If MsgBox Invoked in LostFocus Event          http://support.microsoft.com/support/kb/articles/q85/8/56.asp

             Validating Text Box Data Causes Extra LostFocus Events    http://support.microsoft.com/support/kb/articles/q96/8/46.asp
For some work around.

If you have further questions or problems, let me know.

Regards
Dalin
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1433710
Quarek,
  What do you do after the message Box? Is your text box in the main form? Post/email me the code in the textbox lost_focus and the procedures your are calling if you still have problem. My E-mail: Dalin_N@MAilExcite.com.
Regards
Dalin
0
 

Author Comment

by:quark031698
ID: 1433711
I simply need to know how I can suppress the main
(startup) form coming up unvoluntarily

- the text box is not in the main form,
  is has its own form
- after the message box the control is given back
  to the form where the text box is located
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:clifABB
ID: 1433712
Is the form that has the textbox an MDIChild of the main form?
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1433713
Quark,
If you do not need the main form, Try to put the code in the Lost_focus event, add frmMain.Visible =False or Set frmMAin=Nothing (If you dont need it) before you validate the data.

The main form will come out if you refers to something in the process. In the procedure you are calling, do you use anthing from the main form at all? Was the main form in the background or is it unloaded? Can you post the code inthe lost_focus event and the procedure it Calls?

Let me know if more problems.
Regards
Dalin




0
 

Author Comment

by:quark031698
ID: 1433714
It is not. I also tried to switch the main (startup) form
into an MDIform (and set accordingly the form with the textbox
to being an MDIChild of it) but the result was a different look-and-feel.
However, the problem disappeared, the main form kept staying
in the background as it should. The problem is I cannot accept
the different look-and-feel of the MDIform. Thus I need a
solution without using MDIforms.

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1433715
I'm sorry, I wasn't suggesting you use MDI forms, but had you been doing so, this might have been your problem.

In the main form's load event, do you have code that amounts to:
frmMain.Show
or
frmMain.Visible = True
?

When you refer to a control on a form, it causes that form to load (firing the Load event) if it's not already loaded.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1433716
I believe you have somewhere refers to something in the mainform, and triggler the mainform to show. That does not explain the aotumaticaly disappear, through.  If you still have the problem, after set visible to false, I can look at your code if you like. My e-mail: Dalin_N@MailExcite.com
Using LostFocus with MsgBox is tricky, through. It can cause enexpected results.
Regards
0
 

Author Comment

by:quark031698
ID: 1433717
To set the visibility to false within the *_LostFocus procedure
is a solution. However, it does not match the SW architecture
I have in mind. In this architecture the behaviour of a form
should be determined by that form itself, not by others changing
it. I need a solution with the main form setting itself to the
behaviour of always staying in the background.

Thanks for your attention so far!

Regards,

Wolfgang
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1433718
Quark,

Put a break on the 1st line of code in the *_lostFocus sub, and then excute line by line by pressing F8. You should be able to see when the mainform comes up. Let me know the results.

Regards
Dalin

0
 
LVL 18

Accepted Solution

by:
deighton earned 200 total points
ID: 1433719
I would recommend setting a breakpoint in your lost focus event.  Step through the code from this point.  At some point int the main form initialise or load event you must be doing something to diasplay the form. e.g. Me.show for example
Have you considered putting the validation function in a BAS module, this is also more efficient.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1433720
deighton,
Isn't that what I already suggested?
0
 
LVL 18

Expert Comment

by:deighton
ID: 1433721
Dalin - yes sorry it is, but your comment wasn't there when I started investigating the problem - your comment came just 15 mins before mine.  You could have made your comment into an answer!


0
 
LVL 9

Expert Comment

by:Dalin
ID: 1433722
deighton,
I see. However, this is not the soltion to the problem, it is just a way to search for the problem, that why I did not provide it as the answer.
Regards
Dalin
0
 

Author Comment

by:quark031698
ID: 1433723
I leave as it is. The problem is now being investigated
by some other people in my department.
But thanks anyway.

Best,

Wolfgang
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change the path of the data source in my Excel pivot table with macro 4 47
MsgBox 2 59
MS Date Picker 64 bit 32 bit issue 12 59
Zip Folders Using Chilkat Routines 1 58
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question