Solved

main form is shown undeliberately

Posted on 1998-04-29
15
304 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

863 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

25 Experts available now in Live!

Get 1:1 Help Now