Basic Tables Question

C

Chuck Hildebrandt

I have Access 2003. It seems when I change a record, and go to close the
sheet, there is no prompt asking me if I want to save the changes or cancel,
which is certainly standard in Excel and Word. Is this by design? If so,
is there any way to make it prompt? It seems it might be a problem if I
change a record by mistake.

Thanks.

Chuck
 
E

Ed Warren

This is by design. As each record is edited it is posted back to the
database. The developer can build a prompt when the 'onupdate' event fires
and/or can add appropriate field validation values to the application.
However, these should be used in a manner to make sure the user experience
is still appropriate.


Ed Warren.
 
T

Tom Lake

Chuck Hildebrandt said:
I have Access 2003. It seems when I change a record, and go to close the
sheet, there is no prompt asking me if I want to save the changes or
cancel, which is certainly standard in Excel and Word. Is this by design?
If so, is there any way to make it prompt? It seems it might be a problem
if I change a record by mistake.

That's the was Access is. What I do is to create a form used for Add mode
only with all unbound fields then when an update button is pressed, I add
the
contents of the fields to the table. If the Cancel button is pressed
no update occurs. It's more work but it is a lot safer.

Tom Lake
 
P

Pat Hartman\(MVP\)

That's the BeforeUpdate event, not onupdate. The BeforeUpdate event should
be cancelled if any errors are detected or if you prompt the user and he
says not to save. Use:

Cancel = True

to cancel the BeforeUpdate event. You can use .SetFocus to set focus back
to a control that needs correcting and you can use MsgBox to display
messages. For example:

Private Sub Form_BeforeUpdate (Cancel As Integer)
If IsNull(Me.SomeField) Then
MsgBox "Some Field may not be null", vbOKOnly
Cancel = True
Me.SomeField.SetFocus
End If
If Me.SomeDate > Date() + 7 Then
MsgBox "Some Date must not be more than one week in the future",
vbOKOnly
Cancel = True
Me.SomeDate.SetFocus
End If
End Sub
 
P

Pat Hartman\(MVP\)

There is no need to go through all that work. All you need to do is
understand how to use the form's BeforeUpdate event properly to have
COMPLETE control over whether or not a record gets saved.
 
E

Ed Warren

Of course you are correct, thanks

Ed Warren

Pat Hartman(MVP) said:
That's the BeforeUpdate event, not onupdate. The BeforeUpdate event
should be cancelled if any errors are detected or if you prompt the user
and he says not to save. Use:

Cancel = True

to cancel the BeforeUpdate event. You can use .SetFocus to set focus back
to a control that needs correcting and you can use MsgBox to display
messages. For example:

Private Sub Form_BeforeUpdate (Cancel As Integer)
If IsNull(Me.SomeField) Then
MsgBox "Some Field may not be null", vbOKOnly
Cancel = True
Me.SomeField.SetFocus
End If
If Me.SomeDate > Date() + 7 Then
MsgBox "Some Date must not be more than one week in the future",
vbOKOnly
Cancel = True
Me.SomeDate.SetFocus
End If
End Sub
 
Top