Save Record On Another Form Via Code

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi,

I am trying to save a record on a parent form using code.

The code is basically.

me.form.parent.setfocus
runcommand accmdsaverecord

This always results in an error "record cannot be saved now" and the record
remains unsaved.

I have added the Save Record button to the toolbar, and that saves the
record just fine (so it is not a case of mandatory fields not being
completed).

What are alternate ways in code of saving the record currently displayed on
a given form?

As the Save Record button is not on the standard menus (you have to
customise) docmd domenuitem is not going to help.

I'm about to resort to a Shift+Return via sendkeys, but that is pretty
nasty.

Any suggestions would be greatly appreciated.

TIA

Paul
 
You could try:

Me.Parent.SetFocus
Runcommand acCmdSaveRecord

Better still:

With Me.Parent
If .Dirty Then
.Dirty = False
End If
End With
 
Thanks Allen I'll give that a try.

I've discovered that the problem I was having is that you cannot do a save
after just setting the focus to the form (with the runcommand version), you
have to set the focus to a control on the form - don't know why, but it is a
pain as you have to cycle through the controls until you can find one that
can accept the focus (not locked, disabled, invisible, etc).

I'll give your suggestion a try.

Thanks

Paul
 
Your suggestion works great - thank you.


Paul said:
Thanks Allen I'll give that a try.

I've discovered that the problem I was having is that you cannot do a save
after just setting the focus to the form (with the runcommand version), you
have to set the focus to a control on the form - don't know why, but it is a
pain as you have to cycle through the controls until you can find one that
can accept the focus (not locked, disabled, invisible, etc).

I'll give your suggestion a try.

Thanks

Paul
 
Back
Top