Save & new button

Ravi Kumar

Registered User.
Local time
Today, 19:00
Joined
Aug 22, 2019
Messages
162
I've written a small code to save & new button , but unfortunately it is not working. Someone please help me.
#Private Sub cmdsavenew_Click()
If Me.Dirty = True Then
If MsgBox("Do you want to save the changes for this record?", _
vbYesNo + vbQuestion, "Save Changes?") = vbNo Then
Me.Undo
Else
Me.Dirty = False
DoCmd.Save acForm, "2019"
DoCmd.OpenForm ("2019"), acNormal
End If
End If
End Sub
 
what is not working?
Code:
Private Sub cmdsavenew_Click()
If Me.Dirty = True Then
    If MsgBox("Do you want to save the changes for this record?", _
              vbYesNo + vbQuestion, "Save Changes?") = vbNo Then
        Me.Undo
    Else
        Me.Dirty = False
        DoCmd.GoToRecord ,,acNewRec
    End If
End If
End Sub
 
it is not showing new form after saving .& also I think it works only if the changes are made to the form ,but I need to open a new form even when no changes are made to the form.
Other wise I have to keep another new button ,which I don't want to.
 
dear sir , sorry to say but still the problem is unresolved,
actually what I want is :

* Even if no changes are made to existing form(record),& if I click on save & new It should open a new form.
* Suppose if I did any changes to the existing record or enter a new record it should show a message box asking whether to save or not , if I click yes it should save & got to new record.
* If I click no it should do nothing.
hope this helps to solve my issue.
 
Code:
Private Sub cmdsavenew_Click()
If Me.Dirty = True Then
    If MsgBox("Do you want to save the changes for this record?", _
              vbYesNo + vbQuestion, "Save Changes?") = vbNo Then
        Me.Undo
    Else
        Me.Dirty = False
        DoCmd.GoToRecord ,,acNewRec
    End If
Else
    Docmd.GotoRecord , , acNewRec
End If
End Sub
 
you're welcome.
 
If you changed your thought processes and made the button create the New Record, you would get what you want.?
If the record was dirty, you would get your prompt, if not, you would still get your new record.

I would be coding as Pat recommended. Any time I see that I have duplicated code in various paths, I know there is better logic to be used.
 
By the way, and she is usually pretty cool about this so don't worry about the error, but ... Pat Hartman isn't a "Sir" she's a "Ma'am."
 

Users who are viewing this thread

Back
Top Bottom