[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

check if acUndo available

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
wj53
Asked:
wj53
  • 3
  • 3
  • 2
  • +2
1 Solution
 
hongjunCommented:
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
 
hongjunCommented:
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
 
hongjunCommented:
Ignore the first post by me. It is utter rubbish. Use the second one. It will work.

hongjun
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
aikimarkCommented:
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
 
wj53Author Commented:
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
 
aikimarkCommented:
If me.dirty then

End If

or

Select Case rs.EditMode
  Case dbEditInProgress , dbEditAdd

End Select
0
 
wj53Author Commented:
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
 
aikimarkCommented:
You should place the code in the QueryUnload event.
0
 
DanRollinsCommented:
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
 
NetminderCommented:
Per recommendation, points refunded and question closed.

Netminder
EE Admin
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now