Results 1 to 4 of 4
  1. #1
    Jmeyering is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    10

    Selecting record in foreign table using VBA

    Is it possible to select a value from a foreign table using vba? The code is going to be executed automatically every month.



    I can get the variable I want using a SQL statement, it is possible to pass a SQL value into a variable? For Instance the following SQL selects the value that I need, I know this doesn't work but hopefully you can understand what I mean.

    Code:
        EmailAddress = "SELECT tblGuardians_RepPayee.Email FROM tblGuardians_RepPayee INNER JOIN tblClients ON tblGuardians_RepPayee.GuardianPayeeID = tblClients.RepPayee WHERE tblClients.ClientID=" & rst![ClientID] & ";"
    I'm running reports based off tblPettyCashTransactions and need to the RepPayee Email address to email the report. My table struture is set up like this

    tblGuardians_RepPayee
    GuardianID
    ...
    Email

    tblClients:
    GuardianId
    ...

    tblPettyCashTransactions
    ClientId
    ...

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Sure; you'd have to open a recordset on the SQL or use DLookup(), which you may find simpler:

    DLookup Usage Samples

    Because of the join, you'd need to be looking up from a query rather than a table.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Jmeyering is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    10
    Nailed, it Thanks So much!

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    No problemo!
    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. My first access database - new foreign key record
    By michal_milena in forum Access
    Replies: 1
    Last Post: 10-21-2012, 03:30 PM
  2. Replies: 2
    Last Post: 06-06-2012, 09:35 AM
  3. Replies: 10
    Last Post: 05-08-2012, 09:17 AM
  4. Replies: 9
    Last Post: 09-16-2011, 03:52 PM
  5. Selecting foreign key values on data entry
    By hardya in forum Access
    Replies: 4
    Last Post: 02-11-2010, 11:56 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