链接到组合框值的SQL select查询的语法错误

时间:2015-04-28 10:22:22

标签: access-vba ms-access-2010

在下面的查询中,我尝试根据组合框控件' cboDepartments'中的值检索一组记录。我在下面的例程的连接函数上收到语法错误消息,但不明白为什么。

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

1 个答案:

答案 0 :(得分:1)

在Access中,如果有多个连接,则必须使用括号。试试这个:

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 & "'"