Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Focus Directly Goes to the MS Flexgrid Entercell Instead of the Current Control  LostFocus event

Posted on 2001-06-20
10
Medium Priority
?
1,219 Views
Last Modified: 2012-08-13
Thanks for any ideas.

I am using VB 6.0.  I have a one column MS Flexgrid where a user can click on a repair service number.  A vehicle may have many repair service numbers and a comment for each repair service number.  The application is designed to record a particular repair service number without a comment.  If user decides to quit and not input any comments for that service number, only the repair service number will be recorded.

Service numbers are entered in the system via a textbox.

If I highlight a repair service number in the MSFlexgrid, the correct comments appear in a textbox below.  That works fine.  The application is also designed to automatically record any data in the textbox after the user closes the form, clicks on the same repair service number or different repair service number in the MSFlexgrid.  

Using a lostfocus event in the textbox to record a comment with that service repair number works fine except when clicking on a different service repair number in the MSFlexgrid.  What's happening is when a different service repair number is chosen in the MSFlexgrid, focus goes directly to the MSFlexgrid entercell before going to the lostfocus event, which is responsible for recording the comment with the appropriate service repair number.

I lose data once focus has left the textbox without recording it with the right service repair number.  A MSFlexgrid entercell event houses code for displaying the next record using the arrow keys or mouse pointer click.

Question??????  What can I put in the MSFlexgrid to prevent the system from going to the MSFlexgrid entercell "first" instead of the lostfocus event of the textbox control?  Please explain!  I was under the impression that a lostfocus event would fire before going to another control, in this case, back to the MSFlexgrid.

Thanks    
0
Comment
Question by:BirdsOfFire1
[X]
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
10 Comments
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6212867
yes, thats right, the lostfocus will be triggered, only after, getting focus to another control.

You could use the Validate event for the text box, which I myself found after a very long time.

if you want details, let me know.

hope this helps,
Cheers.
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6213034
If you can create a Public variable

Public PrevServNum as String ' or what ever you require

in MSFlexgrid lost focus event set the PrevServNum to the appropriate setting, then use this variable to store the data.

Then when user click on a new grid line your data will still go to the right place
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6213116
Hornet241,

The question is about lostfocus of TextBox, triggering EnterCell of MSFlexGrid, if I had understood properly.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 43

Expert Comment

by:TimCottee
ID: 6214921
I would slightly modify Hornet241's thoughts:

Set a flag on the form which is set to TRUE in the EnterCell event of the grid, in the leave cell event of the grid, check the status of this flag, if false call the textbox_LostFocus event explicitly otherwise not. Set the flag to FALSE in the lostfocus event to avoid it being called twice. This should handle moving cells in the grid without the focus ever going to the textbox but will still call the textbox_LostFocus procedure if you do.

Hope this helps.
0
 
LVL 9

Accepted Solution

by:
Valliappan AN earned 400 total points
ID: 6215028
You could use the Validate event with whatever code you have in lostfocus event of Textbox, with slight modifications, in case you do Textbox.setfocus on some validation error, then you need to change it as Cancel=True.

Have a look at this:

http://msdn.microsoft.com/library/devprods/vs6/vbasic/vbcon98/vbcstrestrictfocususingvalidationeventcausesvalidationproperty.htm

Hope this helps,
Cheers.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6215032
In case you dont wish to do validation/validate event code on pressing some button, say, Cancel, then you could set the CausesValidation property of the Command button to False.

0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6215120
valli_an

>>>The question is about lostfocus of TextBox, triggering EnterCell of MSFlexGrid, if I had understood
properly.

As I understand it, it's above the Entercell event firing before the lost focus event and changing the row of the flexgrig before an update in the textbox lost focus

0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6216779
ya, Hornet241 you are right. I mentioned of Validate event, so that the lostfocus code, if put in Validate event, then the Validate event will trigger before the EnterCell event of the Flexgrid. So, no problem, because of the lostfocus event.

Thats what I meant. Hope I had understood it properly.

You could check with the MS link, that I had provided, it says, the lostfocus event occurs only after another control gets focus, to avoid that you could use Validate event.

Thank you,
Cheers.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6216787
ya, Hornet241 you are right. I mentioned of Validate event, so that the lostfocus code, if put in Validate event, then the Validate event will trigger before the EnterCell event of the Flexgrid. So, no problem, because of the lostfocus event.

Thats what I meant. Hope I had understood it properly.

You could check with the MS link, that I had provided, it says, the lostfocus event occurs only after another control gets focus, to avoid that you could use Validate event.

Thank you,
Cheers.
0
 

Author Comment

by:BirdsOfFire1
ID: 6229584
All of the participates contributed, but I liked the validate event better.  Used it and it worked.

Thanks Again
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Suggested Courses

618 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