Results 1 to 4 of 4
  1. #1
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151

    Command(s) to clear a subform


    I have a subform based on a related table. I have a button to create a new record in the related table. I need a command or commands to clear the subform when the button for creating a new record is clicked.

    Here is the code I have in the 'on click' event. Note the comment "clear the form," is where I want to put the command(s).



    Private Sub cmdNewbtn_Click()

    Dim tempnum As Long
    Dim recnum As Long

    DoCmd.RunCommand acCmdRecordsGoToLast

    tempnum = TeamID
    tempnum = tempnum + 1

    'clear the form

    DoCmd.RunCommand acCmdRecordsGoToNew
    Me.TeamID = tempnum

    End Sub

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Have you tried using the LinkMaster and LinkChild parameters on the Subform? This links your sub table to the main table and if you go to a new record on the main table, it will then create a blank record on the sub form/table and insert the main table record key ID in that subtable if you enter data there. Then you would not have to use any code.

    So the above code is run on the main form and once done you will be on a new record for the Main form with the next TeamID value, is that right? And the subform values would have remained from the previous TeamID or record so that form is not tied to the main form?

  3. #3
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    I think this is probably the key to my problem. But it raises another question - can you have a subform inside another subform? My data has 3 levels.

    Thanks.

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I believe the max nested subform levels is 7. If your 2nd level subform is to be based on records of the 1st level subform, then you're out of luck wrt Master/Child link between those 2 subforms. However, there might be a work around you can use. Here's one on that subject (see "A subform cannot link...")

    https://www.fmsinc.com/microsoftacce...edSubforms.asp
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Need help with VBA command to clear a form and syntax
    By msmithtlh in forum Programming
    Replies: 4
    Last Post: 07-16-2022, 10:00 AM
  2. Use Command button to clear one table and amend another
    By HotelierDream in forum Programming
    Replies: 7
    Last Post: 12-24-2020, 08:27 AM
  3. Replies: 2
    Last Post: 08-07-2019, 08:37 PM
  4. Replies: 3
    Last Post: 05-16-2012, 10:20 AM
  5. Command button code to clear form
    By windwardmi in forum Forms
    Replies: 15
    Last Post: 11-21-2010, 03:21 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