Results 1 to 4 of 4
  1. #1
    swenger is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    151

    Need to Set Field Value on new record

    I have a few tables linked together. When I have a subform with info from one table, access automatically populates the linked field in the subform to match the main form. However, in my case I have three tables linked and I want one table to be in the main form and then data from the second and third to be on one subform. My subform is based on a query which includes data from the 2 and 3 table. However when I go to the Subform, the linked field is not populated. As a workaround, I simply enter the data in this field to match the main form and can enter the rest of the data on the subform and all is well. However to save some time, I would like to populate this field with VBA when I click on the new record command button I created but I can't get the syntax correct.

    Main Form is called FClient and Table is called Client Linked field is Customer ID
    Sub Form is called FLicense_Detail


    I tried the following different codes but I don't know the correct syntax. Any help is appreciated



    Private Sub New_Click()
    DoCmd.GoToRecord , , acNewRec
    Me.CustomerID = [Forms]![FClient]![CustomerID]
    End Sub

    Private Sub New_Click()
    DoCmd.GoToRecord , , acNewRec
    Forms("FLicense_Detail").CustomerID = [Forms]![FClient]![CustomerID]
    End Sub

    Private Sub New_Click()
    DoCmd.GoToRecord , , acNewRec
    Me.CustomerID = CustomerID.Value
    End Sub

    Thanks,

  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
    Where's the button? This may help with the syntax:

    Forms Refer to Form and Subform properties and controls

    You may have to fill out the other arguments for GoToRecord as well.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    swenger is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    151

    Cool

    Thanks. That link helped. I didn't realize I had to actually type "parent" as opposed to the form name


    Quote Originally Posted by pbaldy View Post
    Where's the button? This may help with the syntax:

    Forms Refer to Form and Subform properties and controls

    You may have to fill out the other arguments for GoToRecord as well.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problem and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 06-23-2014, 07:21 AM
  2. Replies: 3
    Last Post: 08-18-2013, 01:15 PM
  3. Replies: 2
    Last Post: 12-21-2012, 01:57 PM
  4. Replies: 6
    Last Post: 04-17-2012, 10:32 AM
  5. Creating unique record from record and field data
    By arthurpenske in forum Access
    Replies: 3
    Last Post: 08-24-2011, 06:11 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