Getting prompted for confirmation of changing record when record hasn't changed (1 Viewer)

PaulA

Registered User.
Local time
Today, 05:40
Joined
Jul 17, 2001
Messages
416
Greetings -

I am using a method so that if a user changes a record, he/she is prompted to confirm the change ("Do you want to accept the change?"). This prompt comes when the person leaves the record (it is a continuous form).

I find that even if no record is changed, if a person enters a record and then the database application is closed using the "X" in the upper right corner, the use is prompted as above, although there has been no record change. This does not happen when they use the "application.quit" function on a tab using the OnClick event, but only if closing with the upper right corner "X".

My code is:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord = True Then
Exit Sub
Else
If MsgBox("Changes have been made to this record. Do you want to save these changes?", vbYesNo) = vbYes Then
           Me.RecordModified.Value = -1
           Me.UserModifyStamp = NetworkUserName
           Me.ModifyDateTimeStamp = Now()
Else           
           Me.Undo
End If
End If
   
End Sub

I also tried adding a "or me.recordmodified = False" to the top argument but it didn't work. I'm not sure why the prompt is appearing without a record change. Is it because it is not a new record when the record is accessed and it either has to be a new record or the prompt will occur just by accessing the record? Again, this only happens when closing the database as I described above, not through an application.quit command.

Any thoughts or solutions would be appreciated.

Thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:40
Joined
Oct 29, 2018
Messages
21,447
Hi. You may not have manually change the record, but if the BeforeUpdate event is firing, then something (maybe code) has changed the record, as far as Access is concerned. So, do you have any code, which is changing the record in some way?
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:40
Joined
Sep 21, 2011
Messages
14,216
Aren't you just issuing that message if it is not a new record?
 

PaulA

Registered User.
Local time
Today, 05:40
Joined
Jul 17, 2001
Messages
416
Thanks for your replies. I did notice that the choice was new record or generate the prompt. How to I include a function that indicates no change in the record - me.RecordChange = False?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 05:40
Joined
Sep 12, 2006
Messages
15,632
If you set ANY bound field/control when the form opens/current event runs, it will make the record dirty.

Add record selectors, and you will see the triangle change to a pencil to indicate a dirty record.

Note in passing that if you close the form without a constraint being met, the form will hjust close without warning you. Even if you add code in beforeupdate, although you can cancel the record save, the form will still close, and will actually scrap the record. To me, it's disconcerting behaviour, but I can't see a way to stop the form close.
 

Users who are viewing this thread

Top Bottom