Opening a subform on new record

G

Guest

On my "Payments" form I have a subform named "Payment Subform" The main form
opens the existing orders and the subform records payments for those orders.
Each order may have multiple payments therefore, the subform can always be
opened to take a new payment. I used the "RunCommand acCmdRecordsGoToNew" on
the subform "on Load event" to make it to open blank but every time I try to
open the form first it gives me a runtime error "the command RecordsGoToNew'
isn't available now" then if I close the error window the form opens normally
and function the way expected.
 
G

Guest

Hi Moe,

Instead of using the on load event of your subform to move to a new record,
use the On Current event of your main form to jump to your subform, make your
subform move to a new record then jump back to your main form - seems messy,
but there doesn't seem to be much in the way of support for subforms with the
docmd.gotorecord... see the following article:
http://support.microsoft.com/kb/92685

Here's your code eg:
me.SUBFORMNAME.form.CONTROLNAME.setfocus
docmd.gotorecord ,, acNew
forms!MAINFORM.CONTROLNAME.setfocus

Damian.
 
G

Guest

Thanks Damian
But it did not work. "Me.SUBFORMNAME.Form.CONTROLNAME.SetFocus" causes a
runtime error of "Object dosn't support this property or method" or"This is
an invalid methos or expression" I even tried to set focus on the subform
first and then set the focus on its control but that did not work either.
 
Joined
Apr 21, 2009
Messages
1
Reaction score
0
How to Make a Sub Form Open on a New Record

I know this is an old thread and having spent a couple of hours on this very problem I thought I'd share my solution, in the hope that it saves someone else time

In the OnCurrent event of the main form type in the following:

Me!NAMEOFSUBFORM.SetFocus
where NAMEOFSUBFORM is obviously the name of the subform on your main form.
I had to figure this one out and here's how I resolved it.

Then in the OnEnter event of the sub form control on the main form type in the following:

DoCmd.GoToRecord , , acNewRec

Each time you move between records on the main form the focus is set to the sub-form, which causes the sub-form's OnEnter event to fire and as the sub-form now has the focus the DoCmd.GoToRecord , , acNewRec can run.
 

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