Go Back   Access World Forums > Microsoft Access Discussion > General

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 11-01-2005, 07:19 AM   #1
NewfieSarah
Registered User
 
Join Date: Feb 2005
Posts: 193
Thanks: 0
Thanked 0 Times in 0 Posts
NewfieSarah is on a distinguished road
Red face Save button

Hey all I have added a yes no button to my save button, so users have the option to save the record or not. so the save yes works fine, but it is the save no I am having probelms with. I would like to click no, and have the changed not saved, clear that out and go back to the first record again kind of like undo. Thanks! Here is my current code:
On Error GoTo Err_savebtn_Click
PIN.SetFocus
'enable buttons
insbtn.Enabled = True
Command31.Enabled = True
Command63.Enabled = True

'Save the current record
Dim Answer As String
Let Answer = MsgBox("Would you like to save your changes?", vbYesNo, "Save record Confirmation")
If Answer = vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
exitedit
Else
exitedit
Call firstbtn_Click
End If
Exit_savebtn_Click:
Exit Sub

Err_savebtn_Click:
MsgBox Err.DESCRIPTION
Resume Exit_savebtn_Click

__________________
There is always a way to fix a problem you just have to look hard enough to find the answer!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
NewfieSarah is offline   Reply With Quote
Old 11-01-2005, 07:27 AM   #2
ghudson
Newly Registered User
 
ghudson's Avatar
 
Join Date: Jun 2002
Location: USA
Posts: 6,199
Thanks: 1
Thanked 87 Times in 49 Posts
ghudson has a spectacular aura about ghudson has a spectacular aura about ghudson has a spectacular aura about
Here is a more advanced Yes/No/Cancel example using a select case statement for a custom Save Record button...
Code:
Private Sub bSave_Click()
On Error GoTo Err_bSave_Click

    Beep
    Select Case MsgBox("Do you want to save your changes to the current record?" & vbCrLf & vbLf & "  Yes:         Saves Changes" & vbCrLf & "  No:          Does NOT Save Changes" & vbCrLf & "  Cancel:    Reset (Undo) Changes" & vbCrLf, vbYesNoCancel + vbQuestion, "Save Current Record?")
        Case vbYes: 'Save the changes
            DoCmd.RunCommand acCmdSaveRecord

        Case vbNo: 'Do not save or undo
            'Do nothing

        Case vbCancel: 'Undo the changes
            DoCmd.RunCommand acCmdUndo

        Case Else: 'Default case to trap any errors
            'Do nothing
    End Select

Exit_bSave_Click:
    Exit Sub

Err_bSave_Click:
    If Err = 2046 Then 'The command or action Undo is not available now
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_bSave_Click
    End If
    
End Sub
The above code should look very familular to you for I posted the same code in your Message Boxes, Yes/No-Ok/Cancel Buttons thread you started on 10/24/2005.

Also, you need to ditch the built-in wizard code for the old DoCmd.DoMenuItem commands are out of date. Use the DoCmd.RunCommand commands instead.
__________________
.................................................. ......
Searching this forum or Microsoft.com or MSDN.com or Google is a great way to discover and learn the answers to your Access programming questions.

Well if it seems to be real, it's illusion...

I am using Access 2010 with Windows 7

The
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
function on this forum really does work.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

.................................................. ......
ghudson is offline   Reply With Quote
Old 11-01-2005, 07:36 AM   #3
NewfieSarah
Registered User
 
Join Date: Feb 2005
Posts: 193
Thanks: 0
Thanked 0 Times in 0 Posts
NewfieSarah is on a distinguished road
Okay so, I am haivng a bit of trouble with my undo as well. In my add I call my undo incase I didnt mean to add I am undo and go back to the original position I was. But it still saves the record. Why is that?? So Why would there be no code for the No button??
UNDO BUTTON CODE
On Error GoTo Err_undobtn_Click
DoCmd.RunCommand acCmdUndo
exitedit
Call firstbtn_Click
'disable buttons
insbtn.Enabled = True
Command31.Enabled = True
Command63.Enabled = True

Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
If rst.EOF <> False And rst.BOF <> False Then
firstbtn.Enabled = False
previousbtn.Enabled = False
nextbtn.Enabled = False
lastbtn.Enabled = False
editbtn.Enabled = False
deletebtn.Enabled = False
Else
firstbtn.Enabled = True
previousbtn.Enabled = True
nextbtn.Enabled = True
lastbtn.Enabled = True
editbtn.Enabled = True
deletebtn.Enabled = True
End If

Exit_undobtn_Click:
Exit Sub

Err_undobtn_Click:
MsgBox Err.DESCRIPTION
Resume Exit_undobtn_Click

End Sub

__________________
There is always a way to fix a problem you just have to look hard enough to find the answer!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
NewfieSarah is offline   Reply With Quote
Old 11-01-2005, 08:13 AM   #4
ghudson
Newly Registered User
 
ghudson's Avatar
 
Join Date: Jun 2002
Location: USA
Posts: 6,199
Thanks: 1
Thanked 87 Times in 49 Posts
ghudson has a spectacular aura about ghudson has a spectacular aura about ghudson has a spectacular aura about
Using the forums code tags makes it a lot easier to read a posters code.

The current record will be saved if the record is dirty [modified] and you move to another record. You would have to trap for the dirty record and not allow the user to move to another record until the dirty record is either saved or the user undo's the changes to the current record.

I use the method posted in my A Better Mouse Trap? sample to prevent that problem.

Check these two links out for a couple of working sample files and ideas...

A Better Mouse Trap?

Enable/Disable The Control Box X Button
__________________
.................................................. ......
Searching this forum or Microsoft.com or MSDN.com or Google is a great way to discover and learn the answers to your Access programming questions.

Well if it seems to be real, it's illusion...

I am using Access 2010 with Windows 7

The
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
function on this forum really does work.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

.................................................. ......
ghudson is offline   Reply With Quote
Old 11-02-2005, 10:07 AM   #5
NewfieSarah
Registered User
 
Join Date: Feb 2005
Posts: 193
Thanks: 0
Thanked 0 Times in 0 Posts
NewfieSarah is on a distinguished road
okay back to this again... the code that you posted in the first message looks great, however I save and it saves and cancel and it undos and if I say no not to save, then it still saves the record!! So what is on the go with that? There must be some kind of code out there that doesnt save the record. that is what I was trying to say, I havent looked at the code for the mouse thing yet, so I will in a few, although it sounds very confusing!!! okay thanks
__________________
There is always a way to fix a problem you just have to look hard enough to find the answer!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
NewfieSarah is offline   Reply With Quote
Old 11-02-2005, 10:37 AM   #6
NewfieSarah
Registered User
 
Join Date: Feb 2005
Posts: 193
Thanks: 0
Thanked 0 Times in 0 Posts
NewfieSarah is on a distinguished road
that is a great save, however I just have one question what is the form before update() doing?? What is that code for? and the form current what is that code doing?? Thanks
__________________
There is always a way to fix a problem you just have to look hard enough to find the answer!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
NewfieSarah is offline   Reply With Quote
Old 11-02-2005, 11:07 AM   #7
NewfieSarah
Registered User
 
Join Date: Feb 2005
Posts: 193
Thanks: 0
Thanked 0 Times in 0 Posts
NewfieSarah is on a distinguished road
I Am Still Haveing The Same Problem With Me Add Button, No Matter What I Do The Record Still Saves Even Though I Have Said No And I Cant Cancel And Undo Cause I Am Still In Edit Mode, Andi Cant Edit When I Am In Edit Mode!! Any Ideas??
Thanks

__________________
There is always a way to fix a problem you just have to look hard enough to find the answer!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
NewfieSarah is offline   Reply With Quote
Old 11-02-2005, 11:22 AM   #8
ghudson
Newly Registered User
 
ghudson's Avatar
 
Join Date: Jun 2002
Location: USA
Posts: 6,199
Thanks: 1
Thanked 87 Times in 49 Posts
ghudson has a spectacular aura about ghudson has a spectacular aura about ghudson has a spectacular aura about
I can not guess what is going on. You will have to post your db. Leave a few dummy records to play with and explain what you want each button [in question] to do and also explain what each button [in question] is actually doing.

If you are correctly testing and trapping if the record is dirty then you will not be able to add a new record if the current record is dirty. My mouse trap sample is very easy to follow if you take the time to read the code for each command button.

__________________
.................................................. ......
Searching this forum or Microsoft.com or MSDN.com or Google is a great way to discover and learn the answers to your Access programming questions.

Well if it seems to be real, it's illusion...

I am using Access 2010 with Windows 7

The
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
function on this forum really does work.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

.................................................. ......

Last edited by ghudson; 11-02-2005 at 11:25 AM.
ghudson is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Close button reappearing even though close button property is set to "No" watrout Forms 3 03-23-2009 01:01 PM
textbox button le888 Forms 13 04-13-2004 12:46 PM
Command button and textbox button le888 Forms 2 04-05-2004 01:32 PM
Saving Record only when Save Button Pressed Bert666 Forms 2 03-06-2003 07:45 PM
How to undo or prevent a record save from a cancel button? Jovalle Modules & VBA 3 05-18-2000 07:34 PM




All times are GMT -8. The time now is 01:55 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World