Results 1 to 4 of 4
  1. #1
    AndycompanyZ is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    80

    Complex query to me anyway

    I have posted this before on another board but I'm stuck with even thinking about how to go about this. I need to create a query so I can build a datasheet off of it. The query will look at a number of tables and select all those delegates who are scheduled onto an event. I then need to do the following which I've written in VBA (and this is pseudocode of what i want to do) but need to translate this into a query somehow:
    If the delegateID in a subteam is = to the SubTeamHeadDelID then


    Show the subTeamParentID and details of this person (who has their details in the delegate details tabel (everyone is in this table)) but if there is no SubTeamParentID in the table then I don't need to do anything.
    I envisage the datasheet as being a list of delegates with columns showing their details and the phonenumber of the person(SubTeamParent or SubTeamDelID) to contact. It seems to me insurmountable in a query. I have the following in VBA:
    Code:
     
    If Me!SubTeamHeadDelID = Me!DelegateID Then
    Dim strID As String
    Dim strID2 As String
    Debug.Print SubTeam
    strID = DLookup("SubTeamParentID", "tblSubTeam", "SubTeam = " & Me!SubTeam)
    
    If strID = Null Then
    MsgBox "You don't need to contact anyone or whatever is needed"
    Else
    strID2 = DLookup("DelegateMobileNumber", "tblDelegate", "ID =" & strID)
    MsgBox "Please contact this SubTeamLeader & strID2", vbOKOnly
    End If
    End If
    which I had hoped to use but the syntax is wrong anyway but I need the same result in a query. I've been reading as much as i can on queries but nothing seems what i want to do. I think it maybe a subquery or 2 one to show who is a delegate and a subteamhead and then one to show who is a SubTeamParent and then include that in my query somehow. I'm a bit confused to say the least.

  2. #2
    AndycompanyZ is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    80
    Have been working on this and now have a query that shows the SubTeamParentID if the SubTeamHeadDelID are the same I imagine I need to put this into another query and use this as a subquery in the sense of Show me the records of delegates scheduled on courses and show me the SubTeamParentIDs of those who are the same as the SubteamHeadDelID. But I don't know how to refer to a subquery within a query

  3. #3
    AndycompanyZ is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    80
    This is my query that gives me a list of all those delegates who are also SubTeamHeadDelIDs (subteam heads) and gives their SubTeamParentID
    Code:
     
    SELECT tblDelegate.ID, tblDelegate.DelegateFname, tblDelegate.DelegateLname, tblDelegate.DelegateMobileNumber, tblDelegate.DelegateEmailAddress, tblEventDelegate.Status, tblDelegate.SubTeamID, tblSubTeam.SubTeamHeadDelID, tblSubTeam.SubTeamParentID
    FROM tblSubTeam INNER JOIN (tblDelegate INNER JOIN tblEventDelegate ON tblDelegate.ID = tblEventDelegate.DelegateID) ON tblSubTeam.ID = tblDelegate.SubTeamID
    WHERE (((tblEventDelegate.Status)=1) AND ((tblSubTeam.SubTeamParentID)=IIf([tblSubTeam].[SubTeamHeadDelID]=[tblDelegate].[ID],[SubTeamParentID],[SubTeamHeadDelID])));
    Now how can i put this in another query that shows all the delegates scheduled.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Hi
    The query you have created can be placed in another query just as you would a table. If you ultimately want to use the SQL of the first query in the second query (as a sub query SELECT statement) I would first check that it gives the required results, then post the SQL statement of the new query. I'm sure there are people here who will be able to help with this.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Help with complex Query
    By CEV in forum Queries
    Replies: 1
    Last Post: 03-12-2011, 06:54 AM
  2. Query too complex error
    By kaledev in forum Queries
    Replies: 9
    Last Post: 02-14-2011, 02:23 PM
  3. Help with complex query (for me at least)
    By GrindEspresso in forum Queries
    Replies: 5
    Last Post: 01-26-2011, 11:03 AM
  4. Complex Query/Queries for a Report
    By Rawb in forum Queries
    Replies: 3
    Last Post: 02-04-2010, 07:44 AM
  5. Complex Update query
    By niihla10 in forum Queries
    Replies: 1
    Last Post: 08-28-2009, 01:02 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