Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ADO - WillChangeRecord Event Examples

Posted on 2012-03-14
8
Medium Priority
?
751 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
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 31

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 your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 31

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 31

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 2000 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 31

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

972 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