Solved

check if acUndo available

Posted on 2002-06-28
10
217 Views
Last Modified: 2008-01-16
Hi,
I want to add a message box(save or not) before closing a form in ACCESS. It seems like the default is save any change when closing a form. as long as user types anything in the form I can use acUndo to discard the changes without saving it. However it user only browse it, it gives me error message says the " action Undo is not available."  How could I check if acUndo is available or not? acUndo always = 0.

here is the code,

Private Sub Form_Close()
'somecode here, if acUndo available...      
If MsgBox("Do you want to save it?", vbYesNo, "Remind") = vbNo Then
   DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, acObjectVerb, acMenuVer70
Else
   Exit Sub
End If
   
End Sub

Thanks,
wj53
0
Comment
Question by:wj53
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
Try this

Private Sub Form_Close()
    'somecode here, if acUndo available...
    If MsgBox("Do you want to save it?", vbYesNo, "Remind") = vbNo Then
        If acUndo = 0 Then
          Exit Sub
     Else
             DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, acObjectVerb, acMenuVer70
     End If
    Else
        Exit Sub
    End If
End Sub


hongjun
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
Or this

Private Sub Form_Close()
On Error Resume Next
    'somecode here, if acUndo available...
    If MsgBox("Do you want to save it?", vbYesNo, "Remind") = vbNo Then
        DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, acObjectVerb, acMenuVer70
    Else
        Exit Sub
    End If
End Sub


hongjun
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
Ignore the first post by me. It is utter rubbish. Use the second one. It will work.

hongjun
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
You can only UNDO a user (or program code intitiated) change, so you will need to check if the form's Dirty property.

You can also check the underlying recordset's EditMode property.  Possible values that would allow UNDO are:
dbEditInProgress and dbEditAdd
0
 

Author Comment

by:wj53
Comment Utility
to hongjun, I tried your method, however, if I open the form and then close it, it still ask me if i want to save it or not.(Eventhough I didn't change anything)

To aikimark, what's the syntax to check the property? I am not quiet familar with VB code.

Thanks for your response.

wj53
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 45

Expert Comment

by:aikimark
Comment Utility
If me.dirty then

End If

or

Select Case rs.EditMode
  Case dbEditInProgress , dbEditAdd

End Select
0
 

Author Comment

by:wj53
Comment Utility
This is what I copied for Dirty event from Help file.

"Note:Modifying a record within a form by using a macro or Visual Basic doesn't trigger this event. You must type the data directly into the record or set the control's Text property."

This is probably why Me.Dirty always eq False no matter I changed something or not.

I think ss long as I am able to test the value for the UNDO in the toolbar, I am all set. but how...?
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
You should place the code in the QueryUnload event.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Hi wj53@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

wj53@devx, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
Comment Utility
Per recommendation, points refunded and question closed.

Netminder
EE Admin
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

771 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