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!

Save/Cancelling Data Entered Into Form 1

Status
Not open for further replies.

jimb51

Technical User
Jun 5, 2004
23
US
Need some help in making my data entry form more 'idiot proof'. User currently bring up a new form in the Add mode by pressing an command button AddJob. Once the user adds the new information, he presses the Close button (which just closes the window) and the new record shows up in the table. What I'd like to happen, is to give the option of SAVE or CANCEL before data is actually transferred to table. Can someone point me in the right direction?
 
You can create command buttons for all of the functions that want to control on the form. You can use the CommandButton wizard and select Record Operation. There then selections for Save Record, Undo, etc. The code is created by the wizard to affect the results that you would want.

Post back with any questions.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
How are ya jimb51 . . . . .

Or something like this in your close button:
Code:
[blue]    Dim Msg As String, Style As Integer, Title As String
    
    Msg = "Are you sure you want to save this record?"
    Style = vbInformation + vbYesNo
    Title = "Save Option . . . . ."
    
    If MsgBox(Msg, Style, Title) = vbYes Then
      DoCmd.RunCommand acCmdSaveRecord
   Else
      Me.Undo
   End If[/blue]
[purple]YourCloseCommand?[/purple]

Calvin.gif
See Ya! . . . . . .
 
I'll try these. Thanks for the quick response!!
 
jimb51: Just a note here to help you out. I setup my forms with this same User "idiot proof" design with buttons to perform all of the functions that they need to or I want to allow them to do. I enable and disable buttons and change the .caption property of my buttons depending on which button is clicked. I also use the Me.Tag property of the form to maintain knowing which status or operation the form is executing at any time.

EXAMPLE:

Buttons: Find, Add Record, Save Record, Cancel, Edit, Exit

When the form is opened the Find, Add Record, Edit, and Exit buttons are enabled and the Save Record and Cancel buttons are disabled. Until something is actually changed on the form or a new record is initiated and entered then the Save Record or Cancel buttons should not be allowed to be clicked.

If the user clicks the Find button then the Add Record, Save Record, Edit, and Exit buttons are disabled. In the OnClick event procedure of the Find button I set the Me.Tag value to "Find". Now if the Cancel button is clicked it knows what operation is in play at this time. You see the code for Canceling the Find operation is different that they code for Cancelling the Add Record operation. So, the code behind the Cancel button has different operations depending upon what operation is executing at the time.

Hope this helps you with your form design.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
The command wizard helped a lot! Don't know why I didn't look for the obvious help -- maybe too much programmer blood in me and not trusting the application to help! I did find a quirk of sorts when I implemented the Save/Cancel buttons. I open the form and a new blank record displays.
--I enter data and pressing Save works as advertised.
--I enter data and pressing Cancel works as advertised -- undoes data input and returns a blank screen.
--I enter no data and pressing Save presents a MsgBox window explanation (I programmed that in using Not Me.Dirty) and returns the cursor to the starting field.
--I enter no data and pressing Cancel returns to new record blank screen.
So far, so good! But......
--I enter data, press Save. Data saved and new blank record screen displays. However, if I now press Cancel, Access deletes that new record I just saved!!

I worked on this a lot this weekend and ended up programming some work arounds but they aren't clean. Any ideas on how to stop that Cancel deletion AFTER a record is saved?
 
First of all after you Enter data, Click Save why are you having the form startup a new record? Why not just stay on the record just saved. Have you programmed in a new record code?

Here is where I keep the user from clicking the Cancel button after a Save. In the OnClick of the Save I disable the Cancel button.

Code:
Me.cmdCancel.enabled = False

Now the problem is solved. As I mentioned above only let the user click buttons that make sense. The Cancel button should only be available for clicking after a new record is started and the first control has data entered into it. Or, if the Edit is clicked and modifications to data has taken place.(i.e. me.dirty). When the user clicks the Edit button I include code to unlock all the controls that they should be able to change/edit and set the Me.tag property to "Edit". Now in the Cancel button code I check first of all for the what process is in place, New Record or Edit.

Hope this helps you out.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Yes, once user Saves record I want to give him the option of entering another new record.

Here is something I discovered which fix the problem: I was just using the default DoMenuItem commands from the command button wizard to Save and Undo. After researching them to be the backward compatibility commands for 97-, I switched to RunCommand commands and PRESTO -- problem fixed!! I still have a small issue of one of my required fields which causes a Form OnError on the Null value if left blank and I try to Save/Cancel/Close. I worked around it for now by disabling the OnError warning message and just putting in an Undo in that section which puts the default value into the field. Causes me to click Close twice but until I work it out, it's functional.

I like your idea of Falsifying command buttons. I'm going to play with that. Thanks for the help!
 
You can determine whether to the form has been updated or not by using the Me.Dirty property.

Code:
If Me.Dirty then
    Docmd.RunCommand acCmdSaveRecord
End if

You can also trap for the specific error message in the error handing routine and keep you from clicking close twice. Why don't you post your code and let me take a look.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Okay, I appreciate the help!
'Customer' is a text field in the Jobs table set to Required=Yes, ZeroLength=No.

JobsFull is the form which takes the input for the table Jobs. The default value assigned for 'Customer' in the JobsFull form is '<Required Entry>'.



'This is the OnError EvtProc I modified to get around the Null value error I was getting when I left the Customer field blank or it just had spaces:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
'Customer is blanked out.
MsgBox "'Customer' does not exist!"
Response = acDataErrContinue
Me.Undo
End Sub

'My SAVE button:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click

If Not Dirty Then
MsgBox " No Changes noted!"
GoTo Exit_cmdSave_Click
Else
DoCmd.RunCommand acCmdSaveRecord
MsgBox " Record Saved!"

'Brings up new blank record screen
DoCmd.RunCommand acCmdRecordsGoToNew
End If
Exit_cmdSave_Click:
DoCmd.GoToControl "Customer"
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub


'My CANCEL button:
Private Sub cmdCancel_Click()
On Error GoTo Err_cmdCancel_Click

If Dirty Then
'Cancels input
Me.Undo
End If
Exit_cmdCancel_Click:
DoCmd.GoToControl "Customer"
Exit Sub
Err_cmdCancel_Click:
MsgBox Err.Description
Resume Exit_cmdCancel_Click
End Sub


'My CLOSE WITHOUT SAVING button:
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

If Dirty Then
Me.Undo
MsgBox " Changes not saved!"
End If
Exit_cmdClose_Click:
DoCmd.Close
Exit Sub
Err_cmdClose_Click:
Resume Exit_cmdClose_Click
End Sub


 
After looking for the same thing for a button to undo the record and close the form I found scriverb's idea to be the best and easiest to maintain. I went a slight step furthe though. Instead of making the control inactive I set my command button to be invisible and when the form becomes dirty I added the following to the On Dirty event

Me.cmdClose.Visible = True

This made the Close button visible when someone entered data into it.

Also I added the following to the After Update event:

Me.cmdClose.Visible = False

This would remove the close button on a new record and befor any datais entered on the new record.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top