繁体   English   中英

使用 VBA 将 Excel 工作表导入 Access 时,如何克服导致运行时 3075 的单元格中的斜杠

[英]When importing an Excel Sheet to Access using VBA how do you overcome slashes in the cell causing runtime 3075

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

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

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

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

无视,我想我应该去:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM