Solved

ADO - WillChangeRecord Event Examples

Posted on 2012-03-14
8
681 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
  • 4
  • 4
8 Comments
 
LVL 15

Expert Comment

by:eemit
Comment Utility
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 29

Author Comment

by:gowflow
Comment Utility
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
Comment Utility
OK gowflow.
Don't use ADODC datacontrol.
Use ADODB intead (because you have complete control).
0
 
LVL 29

Author Comment

by:gowflow
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 15

Expert Comment

by:eemit
Comment Utility
Take a look here.
0
 
LVL 29

Author Comment

by:gowflow
Comment Utility
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
Comment Utility
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 29

Author Closing Comment

by:gowflow
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now