Results 1 to 8 of 8
  1. #1
    PLD60 is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2023
    Posts
    5

    Open new record in a subform

    I have a subform named NotesF within a subform that I am attempting to place a command button to open a new record.



    Code:
    DoCmd.GoToRecord acDataForm, "NotesF", , acNewRec
        DoCmd.GoToControl "NotesDate"
    When I run the code I get the error message, "The object "NotesF" isn't open.

    I think I need to SetFocus on "NotesF" but I can't figure out how to do it.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    you set focus to the subform control first, then the subform itself

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    click the record controller with the * at the bottom. (next to the RIGHT arrow controler)
    that means start new record.

  4. #4
    PLD60 is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2023
    Posts
    5
    Quote Originally Posted by CJ_London View Post
    you set focus to the subform control first, then the subform itself
    Can you recommend to make this happen?

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    Me.subformcontrolname.setfocus
    Me.subformcontrolname.form.somecontrol.setfocus

  6. #6
    PLD60 is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2023
    Posts
    5
    Quote Originally Posted by CJ_London View Post
    Me.subformcontrolname.setfocus
    Me.subformcontrolname.form.somecontrol.setfocus
    I have no idea what to do with this. If I have 3 forms, main form named Form1, 1st subform named Form2, 2nd subform named Form3 how would the above code look?

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    all depends on where your code is in relation to the subform. In your original post you said

    I have a subform named NotesF within a subform that I am attempting to place a command button to open a new record.
    My assumption from this is that there is a main form (unnamed) which has an unnamed subform which in turn has a subform control. But it is not clear whether NotesF is the name of the subform control or the name of the form the subform control contains.

    I also assumed from the above that the button you want to place goes in the unnamed subform

    From your last post

    If I have 3 forms, main form named Form1, 1st subform named Form2, 2nd subform named Form3

    And this assumes the same structure as defined above, the unnamed subform is called Form2
    still not clear whether 'Form3' is the name of the subform control or the name of the form which it contains, but assuming the former:

    Me.Form3.setfocus
    Me.Form3.form.somecontrol.setfocus

    Note: this code edited

  8. #8
    PLD60 is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2023
    Posts
    5
    Sorry, my earlier posts were not very clear.

    I have a main form named [ClientF], a Subform named [DogF], and a second subform named [NotesF]. [ClientF] has a Primary Key and [DogF] has a Foreign Key, both have Field (CustomerID). [DogF] has a Primary Key and [NotesF] has a Foreign Key both named (DogID).

    So, there are clients who have dog(s) and then I write notes on the dogs and the notes are specific to the dogs and the dogs specific to the Customers. (I hope this makes sense).

    With 3 forms it is easy to click on the wrong new record button. So, I want to place a Command Button on the [NotesF] Form that will open a new record on the [NotesF] Form.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 11-14-2019, 05:02 PM
  2. Subform will not open to last record
    By MLangendorf in forum Forms
    Replies: 10
    Last Post: 09-14-2016, 03:51 PM
  3. Replies: 10
    Last Post: 12-17-2014, 03:31 PM
  4. Replies: 8
    Last Post: 08-09-2013, 09:52 AM
  5. Open record from a subform
    By pratim09 in forum Forms
    Replies: 1
    Last Post: 04-28-2011, 12:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums