ADO - WillChangeRecord Event Examples

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
LVL 31
gowflowAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

eemitCommented:
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
gowflowAuthor Commented:
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
eemitCommented:
OK gowflow.
Don't use ADODC datacontrol.
Use ADODB intead (because you have complete control).
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

gowflowAuthor Commented:
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
eemitCommented:
Take a look here.
0
gowflowAuthor Commented:
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
eemitCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gowflowAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.