vbyesno CANCEL??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to "cancel" just close the vb box and go back to the record so
you can make additional changes (without undoing everything already
entered)...
I hope that makes sense. I don't want to say no and trigger the esc type
event where it goes back to nothing in the record.

Thanks!
 
I believe you could use:

vbOKOnly

to do that.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
I appreciate the response but does that cancel and return you to the record
with all of the information?
Here is my code...

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & "Do you want to SAVE changes?"
If MsgBox(strMsg, vbQuestion + vbYesNoCancel, "Save Record?") = vbYes Then
Me.LastEdited = Now
'do nothing
Else
Me.Undo
Cancel = True
End If
End Sub

After the Else... how do I make it just close the VB without making any
changes to already typed info?

Thanks!
 
The Yes No Cancel is somewhat redundant, because there are really only 2
options....yes or no.

Private Sub Form_BeforeUpdate(Cancel As Integer)

if msgbox("Save record?",vbyesno)=vbNo then Cancel = True

'No discard choice for user
If Cancel Then Me.Undo Else me.LastEdited = Now()

'Leave discard choice for user
'If Cancel=false Then me.LastEdited = Now()

End Sub

Cancel causes the record to remain in the edited state. If the user wants
to discard all the changes, they would need to press Esc (twice) or Undo
(twice). The first Esc or Undo reverts the control to its prior state, the
2nd Esc or Undo reverts the record to its prior state. Since you're doing
the Undo programmatically, the user doesn't get a choice to revise the
entries....they'll get discarded. If you want to give the user the choice,
see the commented line.
 
I suspect Access HELP provides a more complete description of the action.

As I understand it, vbOKOnly simply closes the messagebox. That sounds like
what you are trying to do -- have the user acknowledge the message and then
proceed with cancelling the update.

If you are running this in the BeforeUpdate event, you would, as your code
does, use:
Cancel = True
to cancel the update.

The reason for using the "Undo" is if you want to remove the changes made.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Back
Top