Solved

check if acUndo available

Posted on 2002-06-28
10
220 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
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
 
LVL 45

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 45

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 45

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

896 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

11 Experts available now in Live!

Get 1:1 Help Now