Add another JOIN to a sql statement

I have a button on a form that in the click event is points to a sub that builds a sql statement for the data i need. currently the click event is as below but I thought i might be able to add some additional data by editing the first section where it initially builds the sql by adding on more line,
 sql = sql & " AND JOIN tblImpactedTeams ON T_EVC_UE.[Event#] = tblImpactedTeams.[Event#] "
 to what is already there which is
sql = "SELECT T_EVC_UE.*, [SumOfImpact] AS [Customer Impact] "
    sql = sql & "FROM T_EVC_UE LEFT JOIN qryImpactTotal ON T_EVC_UE.[Event#] = qryImpactTotal.[Event#]"

but in adding that line i put a watch on the sql statement and a stop just after it is built and copy it to a blank query and it pops a message saying missing operator. the result is:

SELECT T_EVC_UE.*, [SumOfImpact] AS [Customer Impact] FROM T_EVC_UE LEFT JOIN qryImpactTotal ON T_EVC_UE.[Event#] = qryImpactTotal.[Event#] AND JOIN tblImpactedTeams ON T_EVC_UE.[Event#] = tblImpactedTeams.[Event#] ;

Private Sub Command173_Click()
On Error GoTo Err_Command173_Click

    Dim oApp As Object
    Dim mywhere As String
    Dim mylen As Integer
    Dim sql As String

  '  Set oApp = CreateObject("Excel.Application")
  '  oApp.Visible = True
    'Only XL 97 supports UserControl Property
  '  On Error Resume Next
  '  oApp.UserControl = True
    
    sql = "SELECT T_EVC_UE.*, [SumOfImpact] AS [Customer Impact] "
    sql = sql & "FROM T_EVC_UE LEFT JOIN qryImpactTotal ON T_EVC_UE.[Event#] = qryImpactTotal.[Event#]"
    sql = sql & " AND JOIN tblImpactedTeams ON T_EVC_UE.[Event#] = tblImpactedTeams.[Event#]"
  
    If InStr(1, Me.RecordSource, "WHERE") <> 0 Then
  
        mylen = 0
        mylen = InStr(1, Me.RecordSource, "ORDER") - InStr(1, Me.RecordSource, "WHERE")
        mywhere = Mid(Me.RecordSource, InStr(1, Me.RecordSource, "WHERE"), mylen)
        sql = sql & " " & mywhere & ";"
    Else
        sql = sql & ";"
    End If
    
    Me.sql.Value = sql

    Dim stDocName As String
    Dim stLinkCriteria As String
    
    If InStr(1, sql, "Team") > 0 Then
        sql = "SELECT T_EVC_UE.*, qryImpactTotal.SumOfImpact AS [Customer Impact] "
        sql = sql & "FROM (T_EVC_UE LEFT JOIN qryImpactTotal ON T_EVC_UE.[Event#] = qryImpactTotal.[Event#]) LEFT JOIN tblImpactedTeams ON T_EVC_UE.[Event#] = tblImpactedTeams.[Event#] "
        mylen = 0
        mylen = InStr(1, Me.RecordSource, "ORDER") - InStr(1, Me.RecordSource, "WHERE")
        mywhere = Mid(Me.RecordSource, InStr(1, Me.RecordSource, "WHERE"), mylen)
        sql = sql & " " & mywhere & ";"
        Me.sql.Value = sql
    End If
    
        stDocName = "frmAllInfo"
        DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
    
Exit_Command173_Click:
    Exit Sub

Err_Command173_Click:
    MsgBox Err.Description
    Resume Exit_Command173_Click
    
End Sub

Open in new window

jlcannonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GRayLCommented:
Replace the AND at the start of the second line with INNER.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jlcannonAuthor Commented:
thank you
0
GRayLCommented:
Thanks glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.