Save and Close Form

access2010

Registered User.
Local time
Today, 00:57
Joined
Dec 26, 2009
Messages
1,172
Hello, how could I have one control button to save an entry and than close the form?
At the present time we have two control buttons.
Thank you,
Nicole
===
Save Record
===
Private Sub Save_Record_Click()
On Error GoTo Err_Save_Record_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_Save_Record_Click:
Exit Sub
Err_Save_Record_Click:
MsgBox Err.Description
Resume Exit_Save_Record_Click
End Sub

===
Close form
===
Private Sub Com_exit_Click()
If Me.Dirty And IsNull(Me![Envelope#]) Then
MsgBox "Please enter the vendor envelope number."
Else
DoCmd.Close acForm, Me.Name
End If
End Sub
 
Something
Like?

Code:
If [your validation code here] fails then
    Msgbox "Failed"
    Exit sub
Else
    Me.Dirty=False
    Docmd.Close
End If
 
How many buttons you need for a form depends on the process. It's typical to have one that says Save/Close and one for cancel, assuming cancelling input is applicable. In short, you probably need 2 buttons, just not the way you have them.

EDIT - I notice that you only seem concerned about missing data in closing code but not in saving code. Have you taken care of the possibility that the field has no value when an attempt to save the record is executed?
 
Last edited by a moderator:
access2010: BTW, save buttons don't make any sense if this is not a data entry (or single record edit) type of form. If it is possible to navigate to another record, a save button is pointless.
 
save buttons don't make any sense if this is not a data entry (or single record edit) type of form.
Just realized I was thinking of bound forms. Unbound forms would be a different matter.
 
access2010: BTW, save buttons don't make any sense if this is not a data entry (or single record edit) type of form. If it is possible to navigate to another record, a save button is pointless.
I always put code behine nav buttons and the close button on Single forms
 

Users who are viewing this thread

Back
Top Bottom