Solved

Binding a control to a business object...

Posted on 1998-12-29
9
160 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
ID: 1452955
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
ID: 1452956
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
ID: 1452957
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
LVL 3

Expert Comment

by:traygreen
ID: 1452958
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
 

Author Comment

by:kgrossnicklaus
ID: 1452959
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
ID: 1452960
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
ID: 1452961
no problem...let me give this a try...
0
 

Author Comment

by:kgrossnicklaus
ID: 1452962
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
ID: 1452963
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

792 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