Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Save ONLY when saved

Status
Not open for further replies.

databasesrus

Technical User
May 29, 2003
35
US
I saw a post regarding this and now I can't find it.

IN ACCESS97 how can I make my form NOT save until the Save button is clicked?

Thank you!!
 
I feel the best way is to make the form unbound and filled with unbound fields similar to the ones in the table. Then with a save button one can save it. WROX in their book programming in ACCESS says this is very much faster for a number of users. Their numbr is 100.

rollie@bwsys.net

P.S. This is a very good book and WROX very good publishers.
 
Thank you. I'm not sure that I know how to do that tho. I know how to create unbound fields but how do you then have it save correctly to the table on enter?
 
You will have to input some code within your save buttons OnClick event. Below is a sample:

' First grab all the values from your form.
Dim FirstName
Dim LastName
Dim ChartNoteNo
ChartNoteNo = Me.ChartNoteNo
FirstName = Me.FirstName
LastName = Me.LastName
' Add all your values into the table.
CurrentDb.Execute ("INSERT INTO Tablename(FirstName, LastName, ChartNoteNo) VALUES ('" & FirstName& "', '" & LastName & "', '" & ChartNoteNo &"')")
MsgBox ("Record Saved!")

Let me know if you get stuck.
 
OH I get it. Thank you. I wish there were an easier way but I get what you are saying. Thanks.
 
Another way (and I have not played with this but it should work) is to set a private variable (strSaveButtonClicked = "N") in the "On Current" event. When you enter the record it is now at "N". In the "on Click" event for the save button, set the variable to "Y".

If any fields are changed, the "Before Update" event will be called. In "Before Update", check the value of the variable, if it is still "N", display an approriate message and cancel the event (or give the user the choice of saving or undoing). If the value is "Y", just let nature take it's course.

If you are not sure how to do this, reply back and I will create and send you the code.
 
wow that sounds really cool! would you please?

hey judge did you see my post on the calendar control?
 
Sorry to take so long to get back but I'm so busy at work, I don't feel like going on the computer at home.

Anyway, here's what to do - tested and true.

In the declaration area of the form (at the top before any subs or functions), paste the following:

Private intSaveClicked As Integer


In the "On Current" event for the form paste the following:

intSaveClicked = False

In the "On Click" event for your save button, paste the following (intSaveClicked has to be set to true before the DoCmd call):

intSaveClicked = True
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70



In the "Before Update" event for the form, paste the following:

Dim intRtn As Integer
If intSaveClicked = False Then
intRtn = MsgBox("Save Button was not Clicked - Do You Wish to Save Your Changes?", vbYesNo, "Record was Changed")
If intRtn = 7 Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If
Else
intSaveClicked = False
End If


In the "Before Update" event, you are just checking for a "No" selection. No need to add code for "Yes" selection, let nature run its course.
 
I used an "exit form" command button for the same purpose with the following code & it seemed to work.... On click event for the command button--got the code from VB Help file...
__________________________
'Message Box Warning about unsaved data
Dim CloseResp As String
CloseResp = MsgBox("Any changes made that were not saved by using 'SAVE' button will be discarded!" & Chr(13) & "DO YOU STILL WANT TO EXIT FORM?", vbYesNo, "DATA NOT SAVED")

If CloseResp = vbYes Then
Dim ctlC As Control
'For each control.
For Each ctlC In Me.Controls
If ctlC.ControlType = acTextBox Then
'Restore Old Value.
ctlC.Value = ctlC.OldValue
End If
Next ctlC
DoCmd.Close acForm, "frmNewCase", acSaveNo
Else
txtCaseName.SetFocus
Exit Sub
End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top