?
Solved

check if acUndo available

Posted on 2002-06-28
10
Medium Priority
?
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 7117924
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
ID: 7117928
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
ID: 7117932
Ignore the first post by me. It is utter rubbish. Use the second one. It will work.

hongjun
0
Industry Leaders: 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!

 
LVL 46

Expert Comment

by:aikimark
ID: 7118443
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
ID: 7119902
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
 
LVL 46

Expert Comment

by:aikimark
ID: 7119913
If me.dirty then

End If

or

Select Case rs.EditMode
  Case dbEditInProgress , dbEditAdd

End Select
0
 

Author Comment

by:wj53
ID: 7121950
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 46

Expert Comment

by:aikimark
ID: 7121985
You should place the code in the QueryUnload event.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7964729
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
ID: 8022686
Per recommendation, points refunded and question closed.

Netminder
EE Admin
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

752 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