My code stops after the record saves....form never closes

C

CCripe

Users are going into to update a number, and they want to close the form
before the record gets saved, thus losing their changes.

I created an Exit button, which should save the record change and close the
form. Here's the code:

If Me.Dirty Then
RunCommand acCmdSaveRecord
End If
Forms![frmRMSHours]![Act Hours] = Me![Text9]
DoCmd.Close

If the record is dirty, they press Exit and the record saves. They have to
press Exit again and the form closes. If the record is not dirty, the form
will close when pressing Exit. What am I doing wrong?
 
B

BruceM via AccessMonster.com

To save a record, then close the form:

If Me.Dirty Then
Me.Dirty = False
End If

DoCmd.Close acForm, Me.Name

This assumes you want to close the form that has the command button, not some
other form, in which case you would need:

DoCmd.Close acForm, "FormName"

Actually, you should be able simply to close in this way:

DoCmd.Close

This closes the active window, but seems to me I've have some unexpected
results from doing it that way, so I specify what is to be closed.

I'm not sure what is going on here:

Forms![frmRMSHours]![Act Hours] = Me![Text9]

Is frmRMSHours the current form, another form, or what? If another form, is
it open? What is Text9? In any case, you seem to be adding new data to the
record after saving it. If you are going to do an explicit save, do so after
all new data has been added.


Users are going into to update a number, and they want to close the form
before the record gets saved, thus losing their changes.

I created an Exit button, which should save the record change and close the
form. Here's the code:

If Me.Dirty Then
RunCommand acCmdSaveRecord
End If
Forms![frmRMSHours]![Act Hours] = Me![Text9]
DoCmd.Close

If the record is dirty, they press Exit and the record saves. They have to
press Exit again and the form closes. If the record is not dirty, the form
will close when pressing Exit. What am I doing wrong?
 

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