DoCmd close (1 Viewer)

Pavczech

Registered User.
Local time
Today, 10:10
Joined
Jul 11, 2012
Messages
41
Hello

Is there code which would close the form without recording it in table or specific fields?

something like DoCmd.close acform "Form" acdontsave

Thanks
 

pr2-eugin

Super Moderator
Local time
Today, 10:10
Joined
Nov 30, 2011
Messages
8,494
The word is, acSaveNo

I guess it should have come up in your editor??
 

Pavczech

Registered User.
Local time
Today, 10:10
Joined
Jul 11, 2012
Messages
41
Hi
my understanding of acsaveno is to save the form but nothing to do with the data on the form.
thanks
 

pr2-eugin

Super Moderator
Local time
Today, 10:10
Joined
Nov 30, 2011
Messages
8,494
Try a DoCmd.RunCommand acCmdUndo before the Close?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:10
Joined
Feb 19, 2002
Messages
43,223
All code of this ilk belongs in the FORM's BeforeUpdate event. That is the LAST event that runs before the dirty record is saved. You can prompt to save it and if the user ansers No, you can cancel the update event and undo the changes -

Cancel = True
Me.Undo

There is NO OTHER EVENT that will trap updates in ALL CASES.

If you don't want the form to be able to update data at all, set its AllowUpdates, AllowDeletions, and AllowEdit properties to False.
 

Pavczech

Registered User.
Local time
Today, 10:10
Joined
Jul 11, 2012
Messages
41
Hi I have tried the Form's beforeupdate event and it stops from recording the whole form.

Is there any way how to stop only certain records?

I have this code and I would like it to undo only those 3 records "firstName","Surname" and MonthOfBirth", but record the rest on another related table

Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("[FirstName]", "[VisitorsBook-Personal]", "[FirstName] ='" & Forms![VisitorsBookIn]![FirstName] & "' AND [Surname] ='" & Forms![VisitorsBookIn]![Surname] & "' AND [MonthOfBirth] ='" & Forms![VisitorsBookIn]![MonthOfBirth] & "' ") > 0 Then
Cancel = True
Me!FirstName.Undo
Me!Surname.Undo
Me!MonthOfBirth.Undo
End If
End Sub

Thanks
 

pr2-eugin

Super Moderator
Local time
Today, 10:10
Joined
Nov 30, 2011
Messages
8,494
Why not try in them in the relevant Text box before update event?
 

Pavczech

Registered User.
Local time
Today, 10:10
Joined
Jul 11, 2012
Messages
41
I have tried but when I did it it wouldn't let me input the last record.
It wouldnt accept the "monthofBirth" if that record already existed.
 

Users who are viewing this thread

Top Bottom