Solved

Binding a control to a business object...

Posted on 1998-12-29
9
157 Views
Last Modified: 2013-11-25
I have a database application in which I am binding a number of controls in MDI forms to a business object.  The save button (or menu item) is on the MDI parent form and when it is hit, all items are saved to the business object (and then the database).  

My problem is, when the user edits a field and leaves the cursor in that field (does not press TAB) and clicks on the 'Save' button or menu item, all the changes are made except fot the last change (or the field in which the user was editing upon clicking 'Save').  This sounds trivial to me but I cannot for the life of me figure it out.  The values do not appear to bind to the object until a TAB is pressed. Is there a quick 'Save' update all values?

-Kevin Grossnicklaus
0
Comment
Question by:kgrossnicklaus
  • 5
  • 4
9 Comments
 
LVL 3

Accepted Solution

by:
traygreen earned 50 total points
Comment Utility
You need to manually trigger the Lost Focus event.

Public Sub NextControl()
   If ActiveControl.Name = "txtData" then
      call txtData_LostFocus
   elseif AciveControl.Name = "cboData" then
      call cboData_LostFocus
   etc.....
   end if
End Sub
0
 
LVL 3

Expert Comment

by:traygreen
Comment Utility
The above code belongs in the child form.
You need to call it from the parent form using the <active form>.NextControl
0
 

Author Comment

by:kgrossnicklaus
Comment Utility
I think I accepted this response a little early...after trying the 'LostFocus' idea...It doesn't work at all.  In the MDI child form I call the Control_LostFocus (or whatever) and even stepped through the code (the LostFocus procedure is effectively blank).  Unless I actually physically press tab...no changes are made to the bound field in the recordset.  The validate and lostfocus procedures are both called (I even added a call to the 'Refresh' method, which didn't help)  Any other ideas?
0
 
LVL 3

Expert Comment

by:traygreen
Comment Utility
Where are you actually saving the data, or is it a bound control?
I was assuming that the data was updated (or added to a "dirty queque" on LostFocus)
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:kgrossnicklaus
Comment Utility
It is a bound control to a data class... The whole class works flawlessy (more or less a fancy wrapper around ADO)... The form works great if I make sure I tab out of every field I make changes to before saving the data. If a user leaves the cursor in a field after making changes and hits save, it doesn't reflect the last change.
0
 
LVL 3

Expert Comment

by:traygreen
Comment Utility
When is the update of the data object triggered from the control?
OnChange, LostFocus? Or implicetly? Or are you Previewing keys on the form and looking for the tab key?

{disregard the following if the data object is updated through an event for the control}
Other "Dirty" option that I can think of would be to place the following code in the nextcontrol proc.....
SendKeys "{TAB}"

or a bit "cleaner" (note syntax errors may be present)
{use index assuming array of controls}
DIM lIndex as long

lIndex = ActiveControl.Index

If ActiveControl.Name = "txtData" then
   cboData(0).SetFocus
   txtData(lIndex).SetFocus
elseif AciveControl.Name = "cboData" then
   txtData(0).SetFocus
   cboData(lIndex).SetFocus
etc.....
end if

NOTE - if we.re not progressing adequately, let me know and I will repost using my points to get you an answer.  My initial answer made some assumptions about how you were operating.
Sorry
Tray
0
 

Author Comment

by:kgrossnicklaus
Comment Utility
no problem...let me give this a try...
0
 

Author Comment

by:kgrossnicklaus
Comment Utility
still no luck...tried using SendKeys("TAB") to tab out of the field and also the setfocus command to move among fields (at least to move out of the current field.)  Nothing seemed to work...  My data class performs some validation on the data in the form, and if I enter data in a field in which data is required but do not press TAB it does not find the data I entered.  The Setfocus actually moved the cursor to another field but the data still did not take... If I simply press TAB before clicking the save button on the toolbar it works... Any other suggestions?
0
 

Author Comment

by:kgrossnicklaus
Comment Utility
The text box in question (at least the obvious one I'm using for testing, the problem applies to all the text boxes at least), is set with a data field, source, and member.  Is there anything else I need to do to bind it to my class?  It appears to be bound OK after leaving each field.  The class contains an ADO recordset which contains each of the fields.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…

744 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

18 Experts available now in Live!

Get 1:1 Help Now