Solved

ADO - WillChangeRecord Event Examples

Posted on 2012-03-14
8
718 Views
Last Modified: 2012-03-27
Hello,

I have an ADODC datacontrol in a VB6 Application and on my form have several textboxes bound to this ADODC its name is DatprimaryRS.

I need to know what are the code instructions I need to put to Cancel Update if the user answer No to Do you want to save changes to the record ? that is put in the WillChangeRecord event.

Like ie the user changes textbox1 and textbox2 and textbox3 then realizes he does not want to save the data (we know that in ADO data is saved automatically when you change field) so I want to reverse that change. How to do it ?

Tks
gowflow
0
Comment
Question by:gowflow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 15

Expert Comment

by:eemit
ID: 37719862
Don't use Data Control.
You have much more control if you code all the ADO yourself and just use the normal controls to display the data.

Nevertheless, here is a tutorial about Database Access with the Data Control
0
 
LVL 30

Author Comment

by:gowflow
ID: 37720622
thank you for your answer but seems you did not read my post well !!!
data Control is not my concern !!!! ADO is !!! ActiveX Data Object
gowflow
0
 
LVL 15

Expert Comment

by:eemit
ID: 37720846
OK gowflow.
Don't use ADODC datacontrol.
Use ADODB intead (because you have complete control).
0
Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

 
LVL 30

Author Comment

by:gowflow
ID: 37721303
well for your info, adodc is the datacontrol and in code it translates to
Dim DB as Adodb
Dim RS as Adodb.recordset

Please if you have a clear answer on my inital question please go ahead. It is not about 'don't use this or that' I developp software since over 25 years and not a newbie

I think you are confusing with DAO data control which I am not intrested to use in here for a complex SQL using SHAPE
gowflow
0
 
LVL 15

Expert Comment

by:eemit
ID: 37722126
Take a look here.
0
 
LVL 30

Author Comment

by:gowflow
ID: 37723815
Thank you I have seen already this link and NO it does not help as if you had closely looked it does not use a ADO data control but uses commandbuttons to move next/previous record hence no WillChangeRecord event as this is particular to ADODC !

Tks for trying anyway.
gowflow
0
 
LVL 15

Accepted Solution

by:
eemit earned 500 total points
ID: 37727743
Hi gowflow,

Try this:
Private m_bRecordChanged As Boolean

DatprimaryRS_WillChangeRecord( _
                          ByVal adReason As ADODB.EventReasonEnum, _
                          ByVal cRecords As Long, _
                          adStatus As ADODB.EventStatusEnum, _
                          ByVal pRecordset As ADODB.Recordset _
                          )
  
  If adReason = adRsnFirstChange Then
      m_bRecordChanged = True
  End If

End Sub

Private Sub DatprimaryRS_WillMove( _
                        ByVal adReason As ADODB.EventReasonEnum, _
                        adStatus As ADODB.EventStatusEnum, _
                        ByVal pRecordset As ADODB.Recordset _
                        )
                        
  If m_bRecordChanged = True Then
      If MsgBox("Do you want to save changes to the record?", vbYesNo + vbDefaultButton2, "Save changes") = vbNo Then
          DatprimaryRS.Recordset.CancelUpdate
      End If

      m_bRecordChanged = False
  End If

End Sub

Open in new window

0
 
LVL 30

Author Closing Comment

by:gowflow
ID: 37770196
Hi eemit

I am sorry for the delay in replying I was actually caught in several issues amoung them trying your proposed solution that partially worked. Indeed the key reside in the DatprimaryRS.Recordset.CancelUpdate method that I found but somehow could not get it to work. Your simple post made me redo my calculations and scrapped all of my routines to simply try your solution. I can tell you that puting it in the WillMove event is already too late as it will not undo the update I simply put it under the reason Update in the WillUpdateRecord and it did it perfectly.

The key issue was also to trap and first update in the
If adReason = adRsnFirstChange Then
      m_bRecordChanged = True
  End If
which you did very nicely and smartly.

I apprecaite you sticking with me on this as beeing total newbie on the ADO and had no documentation whatsoever found myself simply drowning in these clauses.

Tks again and I would maybe in the early future post some other issues on the ADO.
gowflow
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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…

751 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