Marchese Il Chihuahua
Marchese Il Chihuahua

Reputation: 1129

Syntax error on an SQL select query linked to a combo box value

In the below query I am trying to retrieve a set of records based on the value in the combo box control 'cboDepartments'. I am getting a syntax error message on the join function for the routine below but don't understand why.

sql_get = "SELECT * FROM ([tblValueChain01] INNER JOIN [tblTeams] ON [tblValueChain01].[Team] = [tblTeams].[ID]) INNER JOIN ([tblContacts] ON [tblValueChain01].[TeamLead] = [tblContacts].[ID]) WHERE ((([tblTeams].[Team])= '" & cboDepartments.Value & "'))"

Me.frmstaticdatadepartments07.Form.RecordSource = sql_get

Upvotes: 1

Views: 82

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172378

In Access you have to use the parentheses when you have more than one join. Try this:

sql_get = "SELECT * FROM ([tblValueChain01] 
      INNER JOIN [tblTeams] ON [tblValueChain01].[Team] = [tblTeams].[ID]) 
      INNER JOIN [tblContacts] ON [tblValueChain01].[TeamLead] = [tblContacts].[ID] 
      WHERE [tblTeams].[Team]= '" & cboDepartments.Value & "'"

Upvotes: 1

Related Questions