Solved

Binding a control to a business object...

Posted on 1998-12-29
9
159 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

810 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