Cancel Table Update from Form

swbrodie

Registered User.
Local time
Yesterday, 20:37
Joined
Apr 9, 2003
Messages
18
Hello.

I have a form that is bound to a table in my database. The form has several text fields and OK and Cancel buttons.

What is the best method for allowing the user to click OK and have changes saved, but not saving changes if they close the window or click Cancel?

I'm sure this is an easy one, and I'm feeling rather stupid about now.

Thanks.

Steve
 
Saving

Using the button from the toolbar and choosing the save button will allow your user to save their current record. Doing this will be automatic and you don't have to worry about code... though it's along the lines of...

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70


you can also add in some error traps by adding...

Dim strMsg As String

If IsNull(text1.Value) Then
strMsg = "No data in the 'text1' field " & vbCrLf & "Please enter data for " & "this field now."
If MsgBox(strMsg, vbQuestion) = vbOK Then
Exit Sub
End If
End If

say for instance if you have a textbox called text1..... this would mean this box has to be filled before you can save

Oh yeah.. you can choose a close form button to close the form too... this will close without saving etc....

HTH

Poot
 
Oh yeah.. you can choose a close form button to close the form too... this will close without saving etc....
This saves the current record also.

If you want to make sure that they always use your button, you'll need to put code into several events.

Dim a public variable for the form
Dim OKSave As Boolean

In the Form's current event:
OKSave = False

In the click event of your Save button:

OKSave = True

In the Form's BeforeUpdate event:
If OKSave = False Then
Cancel = True
msgbox "please SAVE before leaving current record", vbokonly
end if
 

Users who are viewing this thread

Back
Top Bottom