简体   繁体   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

Found a similar post on this question, but it was using an SQL Query and I'm using a DLookup.在这个问题上找到了类似的帖子,但它使用的是 SQL 查询,而我使用的是 DLookup。 I'm importing an Excel sheet to Access.我正在将 Excel 工作表导入到 Access。 I'm getting the run-time 3075 - Syntax error (missing operator)... '[Component]='don't have/want a car'.我收到运行时 3075 - 语法错误(缺少运算符)...'[Component]='没有/想要汽车'。 That particular Component already exists in the DB and it errors out at the comparison.该特定组件已存在于数据库中,并且在比较时出错。

It's either the ' or the / that are causing the hang-up Oh and I went with Variant on the tmpComponent b/c if I go String I get an Object required error at the Set tmpComponent =... line.是导致挂断的 ' 或 / 哦,如果我在 go String 上得到 Object required 错误,我在 tmpComponent b/c 上使用了 Set tmpComponent =... 行。 Maybe that is the problem, just not really sure.也许这就是问题所在,只是不太确定。

Here is my Code and the bold is where the error occurs.这是我的代码,粗体是发生错误的地方。 Thank you in advance for any direction you can provide.提前感谢您提供的任何指导。

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

Disregard, I figured out I should have gone with:无视,我想我应该去:

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

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

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