Avatar of jbakestull
jbakestull
 asked on

Access 2007 Bound form: Close Question

I've noticed that on a data entry form (bound) if a user makes a change to text field and doesn't save the record but exits out of the form, the previous value no longer remains.

What is the best practical way to prevent a user from making changes without prompting a warning message to the user?
Microsoft Access

Avatar of undefined
Last Comment
jbakestull

8/22/2022 - Mon
Rey Obrero (Capricorn1)

use the beforeupdate event of the form

private sub form_beforeupdate(cancel as integer)

if me.dirty then
   if (msgbox ("do you want to save changes made ?",vbyesno))=vbyes then
       me.dirty=false
       else
me.undo
       cancel=true
  end if
end if

end sub
jbakestull

ASKER
I've never used me.dirty before.

Me. dirty = false (highlighted)

When I apply the code, rum time error message that displayed is '2115', the macro or function set to the beforeupdate or validation rule property for this feild is preventing Microsoft Office Access from saving the data in the feild.
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

Well, you can't set Dirty = False in the Form BeforeUpdate event ... because Me.Dirty=False is what triggers the BU event ... And Dirty will already be True in the BU event.

I'm sure Capricorn1 meant a different event ...
Your help has saved me hundreds of hours of internet surfing.
fblack61
Rey Obrero (Capricorn1)

sorry about that, try this revision

private sub form_beforeupdate(cancel as integer)

if me.dirty then
   if (msgbox ("do you want to save changes made ?",vbyesno))=vbyes then
       
       else
       me.undo
       cancel=true
  end if
end if

end sub
ASKER CERTIFIED SOLUTION
jbakestull

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
jbakestull

ASKER
Apply dirty in before event wasn't the best logical choice.