Results 1 to 2 of 2
  1. #1
    NickCarroll is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    8

    Set default value of a form control text box to be the same as a field in a related table


    I have a table called tblJobs which has details of current clients.
    The primary key of this table is jbsID
    In this table are fields for the client's contact name and address: jbsSiteName; jbsAddress1; jbsAddress2 etc.

    I have another table called tblOneOffJobs.
    This table records details of quotations for 'one-off jobs' that are done for the clients in tblJobs.
    The primary key of this table is oojID.
    There's a field in this table called oojJobID which relates to tblJobs on a one-to-many join.
    There are also fields in tblOneOffJobs called oojClientName; oojAddress1, oojAddress2, etc (hold off on the warnings about storing duplicate data for a minute).
    When I create a new record in the child table, tblOneOffJobs, the data entered in oojClientName; oojAddress1, oojAddress2, might be the same as jbsSiteName; jbsAddress1; jbsAddress2 etc., but it might not.
    I want the default values of the name and address fields in the child table [tblOneOffJobs] to be the same as the details in the parent table [tblJobs].
    If the details ARE the same, the user makes no changes however the name and address fields can then be changed if necessary.

    So my question is:
    I've created a form for tblOneOffJobs (based on a query of tblOneOffJobs and tblJobs).
    When the user creates a new record in tblOneOffJobs and selects client from tblJobs, how can I populate oojClientName; oojAddress1, oojAddress2, etc, with values from the related record in tblJobs?
    I think it's something to do with an 'After Update' or 'On Change' event using the DLookup function but I haven't been able to get it working.

    Thank you for reading and hope you can help.
    BTW: Never posted anything in a forum before so please accept humble apologies if I've not followed correct protocol.


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    use 'After Update',
    so if the parent and child data are the same, just copy it:
    if you are on the record, then :

    me.subform.form.txtAddr = me.addr
    me.subform.form.txtSiteName = me.txtSiteName

    if you need the ID, you can put ALL the info in 1 combo box then copy the elements from the combo
    me.subform.form.txtAddr = me.cboBox.column(1)
    me.subform.form.txtSite = me.cboBox.column(2)

    or DLOOKUP (slowest)
    vName = Dlookup("[sitename]","tTable","[siteID]=" & txtID)

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

Similar Threads

  1. Replies: 1
    Last Post: 06-06-2016, 06:05 PM
  2. Value of a text control in a field of a table
    By naahou2000 in forum Access
    Replies: 2
    Last Post: 05-20-2016, 02:41 PM
  3. Replies: 1
    Last Post: 04-07-2015, 06:53 AM
  4. Replies: 12
    Last Post: 06-04-2012, 10:55 AM
  5. Replies: 4
    Last Post: 04-26-2012, 11:04 AM

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