0

在这个问题上找到了类似的帖子,但它使用的是 SQL 查询,而我使用的是 DLookup。我正在将 Excel 工作表导入 Access。我收到运行时 3075 - 语法错误(缺少运算符)...'[Component]='don't have/want a car'。该特定组件已存在于数据库中,并且在比较时出错。

是 ' 或 / 导致挂断哦,我在 tmpComponent b/c 上使用 Variant 如果我去 String 我在 Set tmpComponent = ... 行得到一个 Object required 错误。也许这就是问题所在,只是不太确定。

这是我的代码,粗体是发生错误的地方。提前感谢您提供的任何指导。

Set rsCat = db.OpenRecordset("Categories", dbOpenDynaset, dbSeeChanges)

Dim x As Integer: x = 2
Dim LRow As Integer: LRow = ExLWb.Sheets("Categories").Cells(Rows.Count, 2).End(xlUp).Row
Dim tmpPFId As Variant, tmpCategory As Variant, tmpComponent As Variant, tmpSyntax As Variant, tmpCycle As Variant
Dim NewItem As Integer
NewItem = 0

'*******************  LOOP THROUGH SPREADSHEET UPDATING CATEGORY TABLE
For x = 2 To LRow
  Set tmpPFId = ExLWs.Cells(x, 2)
  Set tmpCategory = ExLWs.Cells(x, 3)
  Set tmpComponent = ExLWs.Cells(x, 4)
  Set tmpSyntax = ExLWs.Cells(x, 5)
  Set tmpCycle = ExLWs.Cells(x, 9)

  **If IsNull(DLookup("[Component]", "[Categories]", "[Component]= '" & tmpComponent & "'")) Then**
     rsCat.AddNew
      rsCat!PF_ID = tmpPFId
      rsCat!Category = tmpCategory
      rsCat!component = tmpComponent
      rsCat!Syntax = tmpSyntax
      rsCat!Active = True
      rsCat!Available = True
      rsCat!Cycle = tmpCycle
     rsCat.Update
     NewItem = NewItem + 1
  End If
Next x
4

1 回答 1

0

无视,我想我应该去:

If IsNull(DLookup("[Category]", "[Categories]", "[Category]= """ & tmpCategory & """ & [Component]= """ & tmpComponent & """")) 那么

于 2020-12-14T13:27:50.127 回答