Results 1 to 4 of 4
  1. #1
    chronister is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    13

    Connections query to link animals together

    Hello all.... Hope everyone is having a good night.



    I am trying to wrap my head around a query. I have the following table w/ sample data....

    connectionID | animal1ID | animal2ID | Notes

    1 30 269 Lucy and Mia were surrendered together.

    The animal1ID and animal2ID fields reference my Animals table with the following (important) fields

    animalID | [Animal Name]

    I have a subform on my main animals page called connections. I am wanting to run a query and find the other animals that the current one is connected to. For instance, (Mia is id 30, and Lucy is ID 269) when on Mia's page the animalID on the form is 30, I want the query to return 269 Lucy [tblConnections.Notes].

    The animal may be listed in either animal1ID or animal2ID. Some animals may be linked to more than one animal such as a litter of cats, or multiple animals that are surrendered together.

    I have tried a combinations of joins and WHERE IN statements and cannot find the right combination here.... any help would be greatly appreciated.

  2. #2
    chronister is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    13
    I have come up with this and it works outside of the form (in a stand alone query and prompts for the Forms![Master Data]![animalID] and works just fine, but when the query is in the subform, it is giving a prompt for animal1ID ... I can enter the test number of 56 (one of the animals I am using for testing) and it works just fine..... but it is not pulling that properly... what am I doing wrong?

    SELECT Animals.animalID, Animals.[Animal Name], tblConnections.Notes FROM Animals INNER JOIN tblConnections ON Animals.animalID = tblConnections.animal2ID WHERE (((tblConnections.animal1ID)=Forms![Master Data]!animalID)) UNION ALL SELECT Animals.animalID, Animals.[Animal Name], tblConnections.Notes FROM Animals INNER JOIN tblConnections ON Animals.animalID = tblConnections.animal1ID WHERE (((tblConnections.animal2ID)=Forms![Master Data]!animalID));


    Thanks in advance

  3. #3
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    Use the expression builder in query to get correct syntax to refer to subform. Like Forms!YourMainformName!YourSubformName.Form!Contro lName

  4. #4
    chronister is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    13
    I got it now. Thanks for help folks. I realized I had not linked the master field correctly and once I did that, it started functioning properly. Thanks.

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

Similar Threads

  1. creating connections between forms
    By premis in forum Access
    Replies: 6
    Last Post: 03-29-2013, 01:21 PM
  2. Query doest not show in Data Connections in Excel 2007
    By adt29 in forum Import/Export Data
    Replies: 4
    Last Post: 03-11-2013, 10:41 AM
  3. Replies: 0
    Last Post: 11-08-2012, 09:34 AM
  4. Multiple connections to a single backend
    By shabbaranks in forum Access
    Replies: 1
    Last Post: 01-09-2012, 04:38 AM
  5. Error using left join accessing 2 active connections
    By peterg2000 in forum Programming
    Replies: 0
    Last Post: 10-05-2009, 05:04 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