Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Select in Subform    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
add new record in subform
Nils Markgraf 
      
3 years ago
I have a problem with selecting records in subform and specifically with adding new records to the subform.
Following code doesn't work on my end:

DoCmd.GoToControl "SubFormControl"
DoCmd.GoToControl "ControlNameOnSubForm"

It shows an error message "Access can not move focus to this control"
But the control is on the form and visible.

Me.SubFormControl.SetFocus
DoCmd.GoToRecord , , acNewRec

This does also not work.
I am trying to add a new record to a subform, by clicking a button on the main form, but I can't figure it out..
Any help would be highly appreciated!

Kevin Robertson  @Reply  
          
3 years ago
Try it like this:

YourSubformName.SetFocus
YourSubformName.Form!YourFieldName.SetFocus
DoCmd.GoToRecord , , acNewRec


Value From a Form
Value From Subform
Nils Markgraf OP  @Reply  
      
3 years ago
Thank you very much for your reply!
Yes I tried that too already.
But still, it just doesn't move to the new record... (only works when I put the code on the subform itself... But that just complicates stuff in my case..)
Kevin Robertson  @Reply  
          
3 years ago
That's weird. I tested the code and it works for me. Can you post a screenshot of your form and the exact code used?
Kevin Yip  @Reply  
     
3 years ago
Hi Nils Markgraf, SetFocus doesn't work in some events, so please post the entire event procedure where SetFocus is used and doesn't work.  Also, a control can't have focus if it is invisible or disabled.
Nils Markgraf OP  @Reply  
      
3 years ago

Kevin Robertson  @Reply  
          
3 years ago
You said in your original post that you are clicking on a button on the parent form. Why are you using an After Update event?
Nils Markgraf OP  @Reply  
      
3 years ago
First of all thank you guys very much for your help!

I narrowed my problem down a bit further:
My subform is actually a subform inside another subform. So it is MainForm.Form!Subform1.Form!Subform2.Form
The DoCmd.GoToRecord , , acNewRec needs to happen on Subform2
The code, which is located in an AfterUpdate Event, is firing on Subform1.

I just tried the whole thing without the nested subforms, so it was only one Mainform and one Subform, then it worked!
But as soon as I try to do it with the two nested subforms, I can't get the DoCmd.GoToRecord , , acNewRec to get working...
The SetFocus still works though.. (my code can be seen on the screenshot above)

Nils Markgraf OP  @Reply  
      
3 years ago
Sorry I was being inaccurate before!
Its not a button, it is a Combinationfield, the code is in the AfterUpdate of that (SuchKombo)
Kevin Robertson  @Reply  
          
3 years ago
Not sure what you mean by CombinationField. I am assuming you mean Combo Box.

Now that we know it is a nested Subform, try this:

Subform1.SetFocus
Subform1.Form!Subform2.SetFocus
Subform1.Form!Subform2.Form!FieldName.SetFocus
DoCmd.GoToRecord , , acNewRec


Replace Subform1 with the name of the outermost Subform.
Replace Subform2 with the name of the innermost Subform.
Replace FieldName with the name of the field on Subform2 you want to set focus.


Again, I have tested this code and it works perfectly for me.
Nils Markgraf OP  @Reply  
      
3 years ago
Oh yeah I mean Combo Box, Sorry! My Access is in german and sometimes I forget the original terms...

This code works, when being placed on the main form.
But my combo box (and therefore the AfterUpdate Event) is placed on Subform1.
And then, the code doesn't work anymore...

I'm really sorry and again I really appreciate your help and your time that you're investing!!
Kevin Robertson  @Reply  
          
3 years ago
Okay, so I set up a test and ran into the same problem trying to go to a new record in Subform2. So made a slight change. Give this a go and let me know if it works.

Subform2.SetFocus
Subform2.Form!ProductName.SetFocus
Subform2.Form.Recordset.AddNew
Nils Markgraf OP  @Reply  
      
3 years ago
YES! That on worked!!!
Thank you so much Kevin!!!
Without your help I would have gone crazy I think.... XD
Kevin Robertson  @Reply  
          
3 years ago
You're welcome.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Select in Subform.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/1/2026 8:17:39 PM. PLT: 1s