Results 1 to 6 of 6
  1. #1
    tylerg11 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    200

    Pull data from a field in a parent record with VBA

    I have a button in a subform that includes pulling the data in a field in the parent record on the main form (i.e. a text box containing a person's name). I'm pretty new to coding, and I think this is probably pretty simple, but I''m just missing it. Would it be a DLookup function?

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You would just need to add a control to the subform and reference the control in the main/parent form that has the info you want.

    The control source for the control on the subform would be as follows

    =forms!YourParentFormName!NameOfControlOnParentFor m

    Of course, you would not store this value in the subform's underlying table since the main form and subform's data sources are already joined (I assume)

  3. #3
    tylerg11 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    200
    Here is the portion of code I am referring to. This button opens an outlook message, and populates it with text strings in my code. The line below should insert the email address from the Email field on the parent form. The code executes as I want it to, but instead of the email adress in the To: field, it inserts the "=forms!frmCompany!Email" portion...what am I missing?

    Code:
    Set objOutlookRecip = .Recipients.Add("=forms!frmCompany!Email")

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I'm never used the particular method you reference but perhaps this

    objOutlookRecip = .Recipients.Add(forms!frmCompany!Email)

    or
    objOutlookRecip = .Recipients.Add(=forms!frmCompany!Email)

  5. #5
    tylerg11 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    200
    I got it now...I was using the wrong method.

    Thanks for that syntax!

  6. #6
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-03-2011, 02:33 PM
  2. Creating unique record from record and field data
    By arthurpenske in forum Access
    Replies: 3
    Last Post: 08-24-2011, 06:11 PM
  3. Replies: 4
    Last Post: 05-17-2011, 06:56 AM
  4. Code to pull in data from a specific record
    By jdunn36 in forum Access
    Replies: 1
    Last Post: 09-20-2010, 11:54 AM
  5. Delete child records with parent record
    By jpkeller55 in forum Access
    Replies: 8
    Last Post: 09-07-2010, 08:52 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