不支持连接表达式 - VBA错误

时间:2017-10-27 05:35:55

标签: vba ms-access

我有以下VBA脚本:

Private Sub CmbTermLookup_AfterUpdate()
Dim BusinessTerm As Integer
Dim SqlString As String
If IsNull(Me!CmbTermLookup) Then
  Me!CmbTermLookup = ""
      Else
    BusinessTerm = Me!CmbTermLookup
End If
SqlString = "SELECT TblBusinessTerm.BusinessTermID,       TblBusinessTerm.BusinessTerm, TblField.FieldID, TblField.FieldName," _
          & " TblField.FieldDescr, TblField.TableID" _
          & " FROM TblBusinessTerm INNER JOIN TblField ON    TblBusinessTerm.BusinessTermID = " & BusinessTerm

Me.RecordSource = SqlString
End Sub

我收到错误 - 不支持加入表达式。

当我在查询中运行sqlstring时它虽然有效。 有什么想法吗?

谢谢

1 个答案:

答案 0 :(得分:0)

您需要在两个表中的每个表中指定一个字段来连接表,然后如果您只想要某些记录,则需要指定WHERE子句:

SqlString = "SELECT TblBusinessTerm.BusinessTermID, TblBusinessTerm.BusinessTerm, TblField.FieldID, TblField.FieldName," _
          & " TblField.FieldDescr, TblField.TableID" _
          & " FROM TblBusinessTerm INNER JOIN TblField ON TblBusinessTerm.BusinessTermID = TblField.BusinessTermID " _
          & " WHERE TblBusinessTerm.BusinessTermID = " & BusinessTerm