Open to new record in subform (1 Viewer)

David Eagar

Registered User.
Local time
Tomorrow, 05:24
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
 

boblarson

Smeghead
Local time
Today, 12:24
Joined
Jan 12, 2001
Messages
32,059
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.
 

David Eagar

Registered User.
Local time
Tomorrow, 05:24
Joined
Jul 2, 2007
Messages
924
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
 

boblarson

Smeghead
Local time
Today, 12:24
Joined
Jan 12, 2001
Messages
32,059
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?
 

David Eagar

Registered User.
Local time
Tomorrow, 05:24
Joined
Jul 2, 2007
Messages
924
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
 

boblarson

Smeghead
Local time
Today, 12:24
Joined
Jan 12, 2001
Messages
32,059
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.
 

David Eagar

Registered User.
Local time
Tomorrow, 05:24
Joined
Jul 2, 2007
Messages
924
database attached, I am trying to get the Sightings subform to open to a new record

Thanks for your attention
 

Attachments

  • Lakes&Species2.zip
    246.2 KB · Views: 129

boblarson

Smeghead
Local time
Today, 12:24
Joined
Jan 12, 2001
Messages
32,059
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.
 

boblarson

Smeghead
Local time
Today, 12:24
Joined
Jan 12, 2001
Messages
32,059
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.
 

David Eagar

Registered User.
Local time
Tomorrow, 05:24
Joined
Jul 2, 2007
Messages
924
mmm I guess what i really want is the cursor to jump to that position
 

boblarson

Smeghead
Local time
Today, 12:24
Joined
Jan 12, 2001
Messages
32,059
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
 

boblarson

Smeghead
Local time
Today, 12:24
Joined
Jan 12, 2001
Messages
32,059
 

suzeg

Registered User.
Local time
Today, 12:24
Joined
Jun 20, 2012
Messages
27
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

Top Bottom