Add New SubForm Record from Main Form

Charmed7

Registered User.
Local time
Yesterday, 19:42
Joined
Jul 23, 2004
Messages
53
I have a main form with a few command buttons which include add a new record to main form which works great. Now I want to add a new Record to the subform. I tried using a macro GoToRecord and named the subform. But it states the subform is not open.

Any help with either Macro or VB statement would be helpful. I just can't get my head around this. I'm sure it's staring at me in the face.

Thanks in advance.
 
A SubForm is not in the Forms collection except through the MainForm. Maybe this link will help.
 
Thank you for the link. It doesn't mean much to me at this point. I will save it so when I do understand, it will become very useful. Could I be so bold to ask if you could spell it out for me? Thank you again.
 
Ok, I'm getting closer. I'm getting error now that states

"An Expression you entered is the wrong data type for one of the arguments"


This is what I put so far. Policy key is just the AutoID. I tried changing the Control to PolicyNumber which is a text box, but I got the same error.

Me.subfrmPolicyInformation.Form!PolicyKey.SetFocus
DoCmd.GoToRecord , subfrmPolicyInformation, acNewRec


Please help. thank you.
 
Ok, Rich helped me with a post from 2002 :) Thank you for baring with me through my solution process. Here's the answer that worked for me.

subfrmPolicyInformation.SetFocus
subfrmPolicyInformation!PolicyKey.SetFocus
DoCmd.GoToRecord , , acNewRec
 
Glad you got it sorted. I had some work to get done and have been offline. Sorry I didn't get back to you sooner.
 
Ok, one more question.

Main form...with subform...with subform.

I need a button on the main form that will create a new record on the sub-sub-form. Any suggestions? I've tried a many different combinations of set focus and it's just not working.

If you need any more details let me know.
 
As you have discovered, setting the focus to a form displayed in a SubFormControl is a two step process. It still holds when trying to get to the next level of SubForm.

Code:
SubFormControl.SetFocus
SubFormControl[b].Form[/b]!NextSubFormControl.SetFocus
SubFormControl[b].Form[/b]!NextSubFormControl.[b]Form[/b]!ControlName.SetFocus
DoCmd.GoToRecord , , acNewRec
Let me know if that does *not* work since I have no sample on which to test it.
 
Ok, I'm getting closer. It did give me a new record on the 2nd subform, but it also gave me a new record on the 1st subform. Any suggestions from there?

Here's the code I put in.


subfrmPolicyInformation.SetFocus
subfrmPolicyInformation.Form!PolicyNumber.SetFocus
subfrmPolicyInformation.Form!subfrmPropertyInformation.Form!PropertyAddress.SetFocus
DoCmd.GoToRecord , , acNewRec

I added the file if that is helpful. The main form name is frmInsuredInformation.

Have I said Thank You lately?
 

Attachments

I only changed a few things and it does *not* demonstrate the problem you described. I would suggest you disable the New Property and Policy buttons until the user has properly defined the Insured. Have fun!
 

Attachments

Users who are viewing this thread

Back
Top Bottom