Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Kendrick, Idaho, USA
    Posts
    277
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Address a subform (2000, XP)

    I have a form with a subform. In the form, I want to place a button that opens a new record in the subform. I think I need to place the address of the subform between the commas in the line of code: DoCmd.GoToRecord , , acNewRec
    Can you help?
    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Address a subform (2000, XP)

    If the code is in the subform, then the GoToRecord action applies to the recordset for that subform. You don't need to specify anything unless the code is being run from the parent form.
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Kendrick, Idaho, USA
    Posts
    277
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Address a subform (2000, XP)

    Yes, the button is in the parent form.

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Address a subform (2000, XP)

    It would probably simplify the process to put the button on the subform rather than the parent - put it on the footer for example. But if you really can't do that then you should be able to do it with
    <font color=blue><font face="Georgia">DoCmd.GoToRecord, acDataForm, "Forms![Primary Form]![Subform Control Name].Form.[Your Subform]", acNewRec </font face=georgia></font color=blue>
    Wendell

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Address a subform (2000, XP)

    An alternative to Wendell's code is to set focus to the subform, then go to a new record:

    Me.SubformControlName.SetFocus
    RunCommand acCmdRecordsGoToNew

    where SubformControlName must be replaced by the name of the subform as a control on the main form (this is not necessarily the same as the name of the subform in the database window.)

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Kendrick, Idaho, USA
    Posts
    277
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Address a subform (2000, XP)

    That worked very well. Thanks. I tried Wendell's method but got a type mismatch error that I have not tracked down. If I still have a problem, this seems to avoid it. Thank you, everyone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •