Results 1 to 4 of 4
  1. #1
    roulette6 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    7

    Using VBA to get data from a parent table record to a child table record (address)

    Hello everyone:

    I've done some searching for this and haven't found anything that solves my issue. I'm an intermediate Access user when it comes to tables, forms, and queries, but am a beginner when it comes to VBA. With that said, here's my question:



    I have a table full of demographic information for a patient in a study. That patient's family members can join and their information is entered in a family member table. Since they often have different addresses, I want to use a check box indicating that the family member's address is the same as the patient's, in which case the corresponding address fields in the family table will pull the information from the patient table. Here's a simplified layout. I am using forms to populate the fields.

    tbl_patient
    patientID [primary key]
    name
    address

    tbl_family
    patientID [linked to primary key in tbl_patient]
    name
    addressSame
    address

    Thank you

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Are you using a form/subform arrangement for data entry - main form bound to patient and subform bound to family?

    Use the checkbox OnChange event and try:

    If Me.checkboxname = vbYes Then
    Me.address = Parent.Address
    Else
    Me.address = Null
    End If
    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.

  3. #3
    roulette6 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    7

    Using a single form

    Quote Originally Posted by June7 View Post
    Are you using a form/subform arrangement for data entry - main form bound to patient and subform bound to family?

    Use the checkbox OnChange event and try:

    If Me.checkboxname = vbYes Then
    Me.address = Parent.Address
    Else
    Me.address = Null
    End If
    Thanks for your reply. Currently, the form for family members is stand-alone and is not embedded in the form for the patient. The reason is that the patient form is fairly long. If necessary, I can make a form for the patient information that includes only the patient address and mark it invisible unless it's as easy to pull the patient's address without the form/subform arrangement.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    In addition to form/subform, consider a tab control on main form to organize other controls, including the subform.

    It would be possible to pull the patient address onto the family form. However, you might find the form/subform arrangement the most convenient for data entry to both tables.
    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: 5
    Last Post: 03-01-2012, 12:59 AM
  2. Replies: 5
    Last Post: 12-22-2011, 11:01 AM
  3. Replies: 10
    Last Post: 01-17-2011, 10:47 PM
  4. Delete child records with parent record
    By jpkeller55 in forum Access
    Replies: 8
    Last Post: 09-07-2010, 08:52 PM
  5. Pulling most recent data from child table
    By davidv43 in forum Access
    Replies: 0
    Last Post: 02-07-2009, 11:36 AM

Tags for this Thread

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