Prompt user to save changes in a form

  • Thread starter Thread starter amyr74
  • Start date Start date
A

amyr74

Hello...
I figured out how to prompt my users to save their changes to an existing
record in a form before closing. However, I was wondering how I can make it
so it only prompts them on existing records and not new. Another words if
they create a new record and add in their data I do not want the prompt to
come up when they go to close the window. I hope I am explaining this
correctly. =)

Thank you in advance for any help you can give. Also...fyi...I am not very
familiar with sql so I need the "dummy" version please =)
 
Sorry again, I dont know a whole about all this. Were in VB do a paste this?
Sorry I know your probably laughing at me. =)

This is what I have in the form so far

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim LResponse As Integer
Dim LMsg As String

LMsg = "!!WARNING!! You are about to change an existing record. Do you wish
to save changes?"
LResponse = MsgBox(LMsg, vbYesNo, "Save changes")

If LResponse = vbNo Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

End If

End Sub

Test the form's NewRecord property:

If Not Me.NewRecord Then
'Run code when not a new record
End If

Steve
Hello...
I figured out how to prompt my users to save their changes to an existing
[quoted text clipped - 6 lines]
Thank you in advance for any help you can give. Also...fyi...I am not very
familiar with sql so I need the "dummy" version please =)
 
amyr74 said:
Hello...
I figured out how to prompt my users to save their changes to
an existing record in a form before closing. However, I was
wondering how I can make it so it only prompts them on
existing records and not new. Another words if they create a
new record and add in their data I do not want the prompt to
come up when they go to close the window. I hope I am
explaining this correctly. =)

Thank you in advance for any help you can give.
Also...fyi...I am not very familiar with sql so I need the
"dummy" version please =)
You do not need to prompt them. Access automatically saves any
changes, whenever you close the form, or move to another existing
or new record.
 
You missed the point, Bob. The OP wants to check and make sure that the user
actually wants to save the change(s) to the existing record! This is pretty
standard if an accidental change to data could create a critical problem.

As Steve said, you have to wrap your code so it only fires if the record
*isn't* a new record. You do that with

If Not Me.NewRecord Then (if the record isn't a new record then do this code)

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim LResponse As Integer
Dim LMsg As String

If Not Me.NewRecord Then

LMsg = "!!WARNING!! You are about to change an existing record. Do you wish
to save changes?"
LResponse = MsgBox(LMsg, vbYesNo, "Save changes")

If LResponse = vbNo Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

End If

End If
End Sub

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
Working like a peach, Thanks so much!!!!!!!!!!!!
You missed the point, Bob. The OP wants to check and make sure that the user
actually wants to save the change(s) to the existing record! This is pretty
standard if an accidental change to data could create a critical problem.

As Steve said, you have to wrap your code so it only fires if the record
*isn't* a new record. You do that with

If Not Me.NewRecord Then (if the record isn't a new record then do this code)

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim LResponse As Integer
Dim LMsg As String

If Not Me.NewRecord Then

LMsg = "!!WARNING!! You are about to change an existing record. Do you wish
to save changes?"
LResponse = MsgBox(LMsg, vbYesNo, "Save changes")

If LResponse = vbNo Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

End If

End If
End Sub
 
Back
Top