Solved

main form is shown undeliberately

Posted on 1998-04-29
15
302 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now