Results 1 to 5 of 5
  1. #1
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Get same info from table based on different id\criteria

    I have a query where I am trying to list 2 employees names each for a different criteria\reason (each query result should list 2 employee names). One of the ID numbers is for an Attendee of an event (working fine), the other ID is the scheduler of that event (not working). I'm not sure how to go about adding the scheduler.

    The scheduler ID is stored in Events.ScheduledBy and the employee ID is Security.ID and name Security.LastName. I can do this with a dlookup but I'd prefer to not use it.

    Original query (without the ScheduledBy part.


    Code:
    SELECT Security.ID, Events.ID, Security.FirstName, Security.LastName, Events.EventDate
    FROM Security, Events, Attendance
    WHERE ((Events.EventDate = txtSearch.Value) AND (Events.ID = Attendance.EventID) AND (Attendance.EmployeeID = Security.ID));
    I tried this, but then it only lists events where the attendee and scheduler is the same person. If I use just Events.ScheduledBy in my SELECT statement, it properly pulls the ID of the scheduledby person, but I want it to pull the name based on that ID. But I need the query to differentiate between the attendee and scheduledby person.
    Code:
    SELECT Security.ID, Events.ID, Security.FirstName, Security.LastName, Events.EventDate, Security.LastName
    FROM Security, Events, Attendance
    WHERE ((Events.EventDate = txtSearch.Value) AND (Events.ID = Attendance.EventID) AND (Attendance.EmployeeID = Security.ID) And (Events.ScheduledBy = Security.ID));
    This provides the result I want, but with DLookUp (if it helps you understand my issue)
    Code:
    SELECT Security.ID, Events.ID, Security.FirstName, Security.LastName, Events.EventDate, DLookUp("[LastName]","Security","[ID]=" & [Events].[ScheduledBy]) As Scheduler
    FROM Security, Events, Attendance
    WHERE ((Events.EventDate = txtSearch.Value) AND (Events.ID = Attendance.EventID) AND (Attendance.EmployeeID = Security.ID));

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    The attendee and scheduler name info are both in the same table (Security)?

    Suggest using join clauses in the query.

    You can include Security table in the query twice. Join one to Attendance and one to Events.

    Join Events and Attendance.
    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
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    Quote Originally Posted by June7 View Post
    The attendee and scheduler name info are both in the same table (Security)?.
    Yes

    Quote Originally Posted by June7 View Post
    Suggest using join clauses in the query.

    You can include Security table in the query twice. Join one to Attendance and one to Events.

    Join Events and Attendance.
    Can you give an example? I've came a long way since I started but never did a join twice in a query.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Use the query builder. Drag the Security table into the design window twice. Click field and drag to other table to create join link between the PK and FK fields.
    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.

  5. #5
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    You're a genius. Thanks again

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

Similar Threads

  1. Replies: 6
    Last Post: 12-11-2013, 01:23 PM
  2. Query for table, based on criteria from other tables
    By PureLoneWolf in forum Queries
    Replies: 2
    Last Post: 10-04-2012, 11:23 AM
  3. Replies: 5
    Last Post: 09-14-2011, 03:41 PM
  4. Replies: 3
    Last Post: 01-31-2011, 11:47 AM
  5. IIF Criteria based on another table
    By BED in forum Queries
    Replies: 6
    Last Post: 11-24-2010, 01:55 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