Add record to subform with click of a button when on main form?

geralf

Registered User.
Local time
Today, 11:39
Joined
Nov 15, 2002
Messages
212
Hi,

Is it somehow possible to use a command button on a main form, that when cliked, adds a new record to a specified sub form? I thought I could use the DoCmd.GoToRecord, acForm, [SubFormName], acNewRec to do this, but I get an error message saying that the [SubForm] isn't open?

Thanks in advance for any help.

Gerhard
 
I think you have to set the focus to the subform control first.
 
Hi,
I'm not getting this to work. Not as long as the button is on the main form. I tried setting focus to the sub form control itsself, and even to a control in the sub form, but I still receive the error form is not open.

Any ideas

Thanks for the reply

Gerhard
 
On a button on the main form add this code to the OnClick event.

PHP:
Me.[b]SubformName[/b].SetFocus
DoCmd.GoToRecord , , acNewRec
 
Cosmos75,

Great....almost :) . I got an error message that said I could not go to that record, so I tried going to the last record instead, and that worked. So now I have the right 'syntax', so now I have to see what causes the error. This is probably caused by some other code, so I'll look ino it.

Thanks very much for the help!
 

Users who are viewing this thread

Back
Top Bottom