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
kgrossnicklausAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
traygreenConnect With a Mentor Commented:
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
 
traygreenCommented:
The above code belongs in the child form.
You need to call it from the parent form using the <active form>.NextControl
0
 
kgrossnicklausAuthor Commented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
traygreenCommented:
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
 
kgrossnicklausAuthor Commented:
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
 
traygreenCommented:
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
 
kgrossnicklausAuthor Commented:
no problem...let me give this a try...
0
 
kgrossnicklausAuthor Commented:
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
 
kgrossnicklausAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.