Creating button to Save Record and Close Form

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.
 
D

Diana Minks

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
 
K

Kieran

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top