Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Subform Focus
Robert Davis 
   
3 years ago
Hi.  I have a parent form with a continuous subform that is a list of companies (sorted A-Z by company name on load).  A Click event in this sub will open a new form to enter info for a new company, save the record and close.  I have a button on the parent form meant to refresh the subform so the new company is shown and the focus moves to that new company.  This is meant to allow the text label to read the primary key of the new record (synchronize subforms video).

Public Sub RefreshScreen_Click()

    Me.Refresh
    Me.MainSub1.SetFocus
    DoCmd.GoToRecord , , acNewRec
    
End Sub

When I click the button, the subform does refresh, and the first record is highlighted - so the first two lines seem to work.  But I get errors trying to move to the new record (I can't use acLast because then it just goes to the bottom record which may not be the newest).  Debug highlights the 3rd line to confirm that's the issue.

Run-time error '2105': You can't go to the specified record.

Any ideas?  Thanks!
Juan C Rivera  @Reply  
            
3 years ago
Open Form to a Specific Record in Microsoft Access

Without a look at the code it's difficult to say.  best guess is your not calling it right.
Bang! v Dot.
try the videos out and hope it answers your question if not hit me back so I can see what you got and maybe point you in the right direction.
Kevin Robertson  @Reply  
          
3 years ago
Is AllowAdditions set to 'Yes' in the Subform?
Kevin Yip  @Reply  
     
3 years ago
Instead of "DoCmd.GoToRecord , , acNewRec", try this and see if it works:

    DoCmd.RunCommand acCmdRecordsGotoNew

The above is the new syntax, and it is identical to clicking on the respective button on the ribbon.  Also check the ribbon to see if the "New" record button is active while you are inside the subform (see picture below).

Also try this:

Click on any record inside the subform, press Ctrl-+ (press and hold Ctrl, then press the plus key), and it should go right to the bottom of the subform and to the new record.  If there isn't a new record to go to, you'll stay where you are.
Kevin Yip  @Reply  
     
3 years ago

Robert Davis OP  @Reply  
   
3 years ago
Note: I have changed some code since my original post.  To answer some of the replies, here is the full process...

Parent form "frmMenu_Main" has a subform control "MainSub1".  The form loaded to this control (SourceObject) depends on a menu and in this case it is loading "frmAssociation_List", which is a continuous form based on "tblAssociation".  Once frmAssociation_List is loaded, it has a list of company names and the company primary key (long integer) hidden.  The first record in the Association table is called "<Add New>" and is always first on frmAssociation_List due to On Load sort order.  Clicking on the Add New record in the list triggers an event housed in that form's builder...

Private Sub AsscLegalName_Click()

    If AsscPK = 1 Then
        DoCmd.OpenForm "frmAssociation_AddNew", , , , acFormAdd
    End If

End Sub

This opens frmAssociation_AddNew in a separate window that allows the user to enter some basic info to get the record started.  They can cancel and no record is created, or save and close the form.

Private Sub btnCancel_Click()

    Me.Undo
    DoCmd.Close acForm, "frmAssociation_AddNew"

End Sub

Private Sub btnClose_Click()

    DoCmd.Save acForm, "frmAssociation_AddNew"
    DoCmd.Close acForm, "frmAssociation_AddNew"

End Sub

Closing the form either way brings the user back to the main menu the same way they left it.  The goal is for frmAssociation_List to update showing the new company in the list as well as move the cursor to that new company (needed for a parent-child link to another subform).  For testing purposes, I added a button to perform what I want to automate eventually.

Note:  The 3 Dim lines are an attempt to get the most recent Primary Key to plug it in somewhere.

Public Sub RefreshScreen_Click()

    Me.Refresh
    Me.MainSub1.SetFocus
    
    Dim MaxKey As Long
    MaxKey = DMax("AsscPK", "tblAssociation")
    MsgBox MaxKey

    DoCmd.GoToRecord , "MainSub1.Form", , "AsscPK=" & MaxKey

End Sub

So far, when I run all this and add a new record using frmAssociation_AddNew, the refresh button partly works...
- The list refreshes and adds the new company in alpha order?  Yes
- The message box pops up with the correct primary key for the newest record? Yes
- Move to that newest record?  No.  I now get "Run-time error '2498': An expression you entered is the wrong data type for one of the arguments.

Ugh

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

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: 4/30/2026 5:13:24 PM. PLT: 0s