Link to home
Start Free TrialLog in
Avatar of kgrossnicklaus
kgrossnicklaus

asked on

Binding a control to a business object...

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
ASKER CERTIFIED SOLUTION
Avatar of traygreen
traygreen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of traygreen
traygreen

The above code belongs in the child form.
You need to call it from the parent form using the <active form>.NextControl
Avatar of kgrossnicklaus

ASKER

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?
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)
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.
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
no problem...let me give this a try...
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?
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.