Open to new record in subform

David Eagar

Registered User.
Local time
Today, 16:57
Joined
Jul 2, 2007
Messages
924
Can anyone point me in the right direction in getting a subform to open to add a new record when the main form is opened? Can do it for the main form, but having grief getting the subform to work

Thanks in advance
 
In the form's On Load event, put
Code:
Me.YourSubformControl.Form.Recordset.AddNew
Where YourSubformControl is the name of the subform control that houses the subform on the main form.
 
Thanks Bob, but didn't work for me. I have a form with data based on a query, with a tab box with several subforms. It still wants to add a new record to the form data, not the subform
 
What other things do you have going on? Does the main form NOT have Data Entry set to YES (which it should be NO) and do you have any kind of record showing on the main form if the code is not there?

What is the final code you used and what is the name of the subform control?
 
Hopefully, pretty straight forward (I'm not clever enough for the advanced stuff yet)

Form loads with data from the main table in read only mode, so details can be viewed but not altered.

Subforms based on linked tables to the main table, which is where I want to be able to add records
 
That could be your problem I think - you're trying to use the same table for a recordsource. I would have to play with it I think to see for sure.
 
database attached, I am trying to get the Sightings subform to open to a new record

Thanks for your attention
 

Attachments

Darn - I don't have 2007 here with me at work. It will be another 3-4 hours before I can take a look. If anyone else looks in the meantime, that is fine. Or, if you want to try to save a 2003 version for me we can see if that helps solve it.
 
Well, for me, I see a new record at the bottom of the subform when I open the form. Does it not do it for you? I see a spot for a new record even without the code.
 
mmm I guess what i really want is the cursor to jump to that position
 
If you want it to do that, set REF's Tab Stop property to NO in the main form and then add the code in red:

Me.frmSightingsSub.Form.Recordset.AddNew
Me.frmSightingsSub.Form.Species.SetFocus
 
yourewelcome.jpg
 
Hello,
I was reading this post and I think this is the answer. I would like to have my cursor jump to the new record in the subform but I do not follow your fix as I cannot download the attachments.
You replied:
If you want it to do that, set REF's Tab Stop property to NO in the main form and then add the code in red:

Me.frmSightingsSub.Form.Recordset.AddNew
Me.frmSightingsSub.Form.Species.SetFocus


Where do I add the code? Novice at VBA.
Thank you
 

Users who are viewing this thread

Back
Top Bottom