The command or action 'SaveRecord' isn't available now

P

pb at work

Hello there,

I am quite new at Access forms and Access VBA. I have a single form which is
nearly completed that is built on bound text boxes.

I can fill the form with the information that I want to save and if i simply
use the tab key to move through each control on the form the record is saved.

However, when I add 'DoCmd.RunCommand acCmdSaveRecord' to the end of my
procedure, I get the error: 'The command or action 'SaveRecord' isn't
available now'

How can I save the records without telling the user to "Tab until you can
tab no more"?

Thank you in advance!
 
K

Klatuu

It is not necessary to tab through all the controls. Any time you move away
from the current record (the one displayed in your form) is is updated. You
do not need to explicitly save the record. The only issue you will need to
address is whether all required fields have data. This is typically done in
the form's Before Update event. For example, let's say that Shoe Size is a
required field and the user tries to move to another record or create a new
record without entering the Shoe Size:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.txtShoeSize) Then
MsgBox "Shoe Size Is Required", vbInformation + vbOkayonly
Cancel = True
Me.txtShoeSize.SetFocus
End If

End Sub

Now if the user fails to enter the Shoe Size, they will get the above
message, the Update will be canceled, and the cursor will be positioned in
the Shoe Size control.

One other point. This code:
DoCmd.RunCommand acCmdSaveRecord
is not the best way to do this. Most professionals would code it like this:
If Me.Dirty Then
Me.Dirty = False
End If
 

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