Results 1 to 6 of 6
  1. #1
    nianko is offline Novice
    Windows XP Access 2000
    Join Date
    Aug 2010
    Posts
    21

    Add a record into a table via a subform


    Hi forum,

    I have a main form with several tabs. This main form is blank and its only purpose is to contain the tabs. Each of those tab has one subform linked to its related table. I would like to be able to enter a new item in one of the table via the subform and I used the following code:

    Code:
    Private Sub Form_Load()
    DoCmd.GoToRecord acDataForm, Me.tblX_AddItems_subform.Name, acNewRec
    End Sub
    where tblX_AddItems_subform is the name of my subform.

    I obtain a msg error from the debogger: "Compile error: Method or data member not found."

    Do you have an idea?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    That's only going to return the name of the subform I think, and you need the full reference.

    http://access.mvps.org/access/forms/frm0031.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    nianko is offline Novice
    Windows XP Access 2000
    Join Date
    Aug 2010
    Posts
    21
    Hi,

    Thanks a lot for the answer. I did have a (prolonged) look at the table and it leaves me a bit confused. I've tried a couple of things, including:

    Code:
    Private Sub Form_Load()
    DoCmd.GoToRecord acDataForm, Me.frmAddItems.tblX_AddItems_subform.Form.Name, acNewRec
    End Sub
    But nothing seems to work (I obtain different types of error now).

    To make things a bit clearer:

    My main form is called "frmAddItems"
    my control (the 6 tabs) is called "TabCtl0" an automatic page I guess
    the specific tab I'm working on is called "x"
    and the subform is called "tblX_AddItems_subform.Form".

    I feel like I've tried all sorts of combinations to get it right, but it's still not working :-(

    I'm not so sure eaither when you use the "!".

    C

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You have .Form in the form name? or do you mean the form name is "tblX_Additems_subform"?

    What is the name of the subform container control? I always name different from the object contained in the control, like ctrAddItems

    Have to first set focus on the subform container control.

    Me.ctrAddItems.SetFocus
    DoCmd.RunCommand acCmdRecordsGoToNew
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    nianko is offline Novice
    Windows XP Access 2000
    Join Date
    Aug 2010
    Posts
    21

    Clarification

    Sorry, let's clarify:
    name of the form: frmAddItems
    I renamed the control as suggested: ctrAddItems (the control that contains the 6 tabs)
    and the name of the subform is: tblX_Additems_subform (there is no '.Form')

    I've tried this:
    Code:
    Private Sub Form_Load()
       ' Me.frmAddItems.ctrAddItems.SetFocus
        DoCmd.GoToRecord acDataForm, Me.frmAddItems.ctrAddItems.tblX_AddItems_subform.Name, acNewRec
    End Sub
    And this:
    Code:
    Private Sub Form_Load()
    Me.ctrAddItems.SetFocus
    DoCmd.RunCommand acCmdRecordsGoToNew
    End Sub
    but to no avail.

    I honestly tied to look for tutorials but it noes not deal with this issue.

    C

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You named the wrong control. Not the tab control - name the subform container control that is sitting on the tab control.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 8
    Last Post: 08-09-2013, 09:52 AM
  2. Replies: 0
    Last Post: 09-17-2012, 03:35 PM
  3. Replies: 6
    Last Post: 08-22-2012, 03:24 AM
  4. Replies: 6
    Last Post: 05-05-2012, 08:43 AM
  5. Replies: 0
    Last Post: 01-06-2009, 02:17 PM

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