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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save or not save records in form on close

Status
Not open for further replies.

tekila

Programmer
Apr 18, 2002
150
SG
How do I generate msgbox to tell the user that he cannot save the records on the form as there are null entities (meaning he has not filled in all the fields in the form)?

And how do I generate another msgbox to ask the user whether he wants to save the records, provided all the fields are not null?

I'm able to check for null entries in form but doesn't know how to write the code to save/not save the records in the form on close.
 
Go to the table that have the fields that are required and set the "Required" Setting to "Yes"...you can also customize the message they get if they don't complete a required field...but I rec that you just let Access tell them.
 
I'm able to check for null entries in form but doesn't know how to write the code to save/not save the records in the form on close.

In most situations, a FORM CLOSE will automatically save changes made to existing records on the form. If you want to be able to NOT commit the changes, you'll need to code in an UNDO process that can be run BEFORE the form is closed.

And I respectfully beg to differ with OutSourceOnCall regarding the message you can give the user if they do not enter a value.

Nothing is more aggravating to a user than getting a message/dialog box that says "Invalid Entry" without telling them WHAT was invalid, or WHAT would be valid.

One gripe with Access's table design DDL is that you can set a validation text for a validation rule, but not for a "Required" rule"..so I'd suggest that you leave REQUIRED set to NO, and set a VALIDATION RULE of "IS NOT NULL", and give an appropriate validation text message:

"Please enter a code from 1 to 4 in the box. This entry is required."

is a helluva lot more user friendly than "One or more values are prohibited by the validation rule "is not null" set for .... "

Your users will thank you for it.




Jim Hare
"Remember, you're unique - just like everyone else"
 
Tried implementing this code but still save record on close.
The funny thing is this code works perfectly well in another form that is without a subform, however it's not working in this form that has a subform. By the way, the subform is requeried in afterupdate event of combo3. Could that be the problem?

Pls advise.
------------------------------------------------------------
Private Sub Close_Click()
Dim strMsg As String

strMsg = "Do you want to save the record?"
If IsNull([combo1]) Or IsNull([combo2]) Or IsNull([combo3]) Then
MsgBox ("There is/are null entit(y/ies). This record will not be saved.")
DoCmd.RunCommand acCmdUndo
Else
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
'do nothing
Else
DoCmd.RunCommand acCmdUndo
End If
End If

On Error GoTo Err_Close_Click

DoCmd.CancelEvent
DoCmd.close

Exit_Close_Click:
Exit Sub

Err_Close_Click:
MsgBox Err.Description
Resume Exit_Close_Click

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top