Results 1 to 2 of 2
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating new record in subform in code (Access 2K, Win 2KPro, SQL Server 2

    I have a form (M) with a subform (A), and on this subform is another subform ([img]/forums/images/smilies/cool.gif[/img]. On the (A) subform, I have a button that adds a new record to the subform, and I want to also have the vb code go to the ([img]/forums/images/smilies/cool.gif[/img] subform and have that move to a new record as well. Since the button is on subform (A), I can use DoCmd.GoToRecord , , acNewRec to create a new record there, but I'm having trouble getting this to work on the ([img]/forums/images/smilies/cool.gif[/img] subform. I can SetFocus easily enough but from there... weirdness.

    With the subform ([img]/forums/images/smilies/cool.gif[/img] selected, I put this in: DoCmd.GoToRecord , acActiveDataObject, acNewRec and get this response:

    The object '-1' isn't open [OK]

    previous attempts to use bang notation to find the subform subform for this requirement have met with no success. I can reference a control on subform (A) in the default on the properties sheet but it doesn't seem to work in code.

    ??

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

    Re: Creating new record in subform in code (Access 2K, Win 2KPro, SQL Serv

    If B is linked to A through its Link Master Fields and Link Child Fields properties, it should automatically display a new record if you move to a new record in A.
    If B is not linked to A, you could use this:

    Me.[BName].SetFocus
    RunCommand acCmdRecordsGoToNew

    where BName should be the name of B as a control on A. This is not necessarily the same as its name in the database window.

Posting Permissions

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