you could unbind the form or handle many events, have you tried something?i don't want the data being entered to automatically save into table
Why?Reason is, i don't want the data being entered to automatically save into table
I understand your concerns, but I would certainly not discard unbound forms considering all the measures one must program against the save-that-record-no-matter-what default behavior of Access. You have gracefully described some of the things one must counter when using the bound form.I would never suggest an unbound form if there's some other way to do the same task, specially to someone who is new to Access.
I would set the Cycle property of the form to current record, add save and undo buttons and use OnClose event to undo before closing if the form is dirty.
User should either save the record or exit without saving.
I guess you haven't viewed any of my videos on the topic.considering all the measures one must program against the save-that-record-no-matter-what default behavior of Access.
Then you need to understand how form events work. You are in total control over whether or not a record gets saved as long as you put your code in the correct event. Using an unbound form because you don't understand how form events work is like using a bazooka to shoot flies. YOU have to reproduce much of the code that MS already wrote for you in the code behind a form. There are reasons to use unbound forms but not because you don't know how to control if a record gets saved or not. See my response to Edgar. You also might want to view one or more of the videos at this link and then download the sample database so you can test for yourself.Reason is, i don't want the data being entered to automatically save into table.. can someone please help me.. thank you in advance..
That is correct, Pat, in the case of bound forms, you have to use the BeforeUpdate event and set its Cancel parameter to True to prevent the update programmatically. In the case of unbound forms, you do not require this event.I guess you haven't viewed any of my videos on the topic.
If you understand how forms work, there is one and only one event you have to work with and that is the form's BeforeUpdate event. That event is like the flapper on a funnel. It is the last event that fires before a record gets saved. Therefore, your validation code goes there - or is called from there if you prefer - and you cancel the event if an error is discovered.
How hard is?
Cancel = True
I'm trying very hard to figure out why "Cancel = True" Is so burdensome that you would recommend an unbound form to a novice. Because "Cancel = True" is all you have to do to get Access to NOT save a record with invalid data, provided of course you know what event to use for validation. There are reasons for using unbound forms but not because you don't know how bound forms work.I understand your concerns, but I would certainly not discard unbound forms considering all the measures one must program against the save-that-record-no-matter-what default behavior of Access.
Private SavedOnPurpose As Boolean
Private Sub cmdCancel_Click()
If Not Me.Dirty Then
MsgBox "There are not updates to cancel.", vbInformation, "No Updates"
Else
MsgBox "Updates canceled.", vbInformation, "Updates Canceled."
End If
Me.Undo
End Sub
Private Sub cmdClose_Click()
DoCmd.Close acForm, Me.Name
End Sub
Private Sub cmdSave_Click()
SavedOnPurpose = True
Me.Dirty = False
MsgBox "Record Saved", vbInformation, "Saved"
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim rtn As Long
If Not SavedOnPurpose Then
rtn = MsgBox("Do you want to Save this record?", vbYesNo, "Save Record?")
If rtn = vbNo Then
Cancel = True
Me.Undo
End If
End If
'Reset
SavedOnPurpose = False
End Sub
Dim tForm As clsTransactedForm
Private Sub Form_Close()
Set tForm = Nothing
End Sub
Private Sub Form_Open(Cancel As Integer)
Set tForm = New clsTransactedForm
tForm.Init Me, "select * from table1;", Me.cmdSaveAdd, Me.cmdSaveEdit, Me.cmdSaveClose, Me.cmdCloseNoSave
End Sub
Sure, but I am pretty sure if the OP is here asking for help to build a simple cancel/save, there is no way they are capable of building even a simple unbound form. The amount of code for load, edit, add, delete, and save would be orders of magnitude more code and more complex code that a simple undo and dirty = false. There are times and places for unbound forms but probably not when the OP statesIt's up to you to test them and make an informed decision about which one is better for you. I recommend the two, as you can see in the first reply to this thread
I am a beginner
Thank You @MajP@Gasman,
Better yet, I will provide the Class to show you can turn any form into a transactional form.
1. Import class into VBE using the File Import.
2. On any form add the following buttons
Save Add
Save Edit
Save Close
Close (No Save)
3. Code on form
Do not give the form a Recordsource, but pass it in instead. Pass in the buttons.
Code:Dim tForm As clsTransactedForm Private Sub Form_Close() Set tForm = Nothing End Sub Private Sub Form_Open(Cancel As Integer) Set tForm = New clsTransactedForm tForm.Init Me, "select * from table1;", Me.cmdSaveAdd, Me.cmdSaveEdit, Me.cmdSaveClose, Me.cmdCloseNoSave End Sub
And as you can see the OP has disappeared.As stated, you have the right to know there are two main ways to program your form and it's up to you to test how you feel more comfortable developing an app.