Creating button to Save Record and Close Form

  • Thread starter Thread starter Keith
  • Start date Start date
K

Keith

Use the VB Editor window to add a line as follows:

Docmd.Close acform, Me.Name

The line should be added immediately after the save
command line of code and before any exit or error handler
label (you can spot those because the line ends in a
colon (:))

That can give problems if there are data entry errors
(like a critical field missing or something), so an
alternative is to add the line of code into the
AfterUpdate event for the form. That way it will never
try to close if there is an error, since it will never
get to the After Update event unless the save operation
works correctly.
 
That didn't work. Here's what I have. This works but
doesn't close the form.

HELP!!!!

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
 
docmd.close



Diana Minks said:
That didn't work. Here's what I have. This works but
doesn't close the form.

HELP!!!!

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
 
Back
Top