Flag in VBA for changes to db

User avatar
pmatz
StarLounger
Posts: 71
Joined: 20 Feb 2010, 10:31
Location: UK

Flag in VBA for changes to db

Post by pmatz »

Is there a way of knowing whether or not any changes have been saved to a database (.mdb file in Access 2010) since it was opened?

Im looking for a trigger on the application.close method that I can check, and if there have been changes, I need to run my backup script.

Currently have a msgbox asking whether to back up or not everytime I close, and since I have been using this db a lot recently, it becomes a bit tedious.
thanks, Paul.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Flag in VBA for changes to db

Post by HansV »

An Access database changes each time you open it, even if you only view some data. And there are no general triggers. So you'd have to define what you consider to be a change.
Best wishes,
Hans

User avatar
pmatz
StarLounger
Posts: 71
Joined: 20 Feb 2010, 10:31
Location: UK

Re: Flag in VBA for changes to db

Post by pmatz »

ok i understand.
i want to ru nthe backup script if any data has changed / been added in any table.
thanks
thanks, Paul.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Flag in VBA for changes to db

Post by HansV »

If all data entry is done through forms, you could use the Before Update event of the forms to set a global variable blnChanged to True. You'd also have to set blnChanged to True whenever you run code that updates, adds or deletes records.

Access 2010 introduces data macros, comparable to triggers in SQL Server, but they only work in .accdb databases, not in .mdb databases.
Best wishes,
Hans

User avatar
pmatz
StarLounger
Posts: 71
Joined: 20 Feb 2010, 10:31
Location: UK

Re: Flag in VBA for changes to db

Post by pmatz »

fair enough, i thought there might be an easier way.
thats gonna be a lot of code to find/add... ;-)
i will use the good old 'if the shift key is pressed when it closes then run it'...
cheers hans
thanks, Paul.