Search code examples
excelvbaimportdlookup

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. I'm importing an Excel sheet to Access. I'm getting the run-time 3075 - Syntax error (missing operator)... '[Component]='don't have/want a car'. 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. 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

Solution

  • Disregard, I figured out I should have gone with:

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