Why do I get this error?

Lopez, Ahiezer 236 Reputation points
2023-07-19T22:33:31.8866667+00:00

Im not sure why I have this code error when trying to import an excel file. Please help.

User's image

User's image

File TypeUser's image

Access
Access
A family of Microsoft relational database management systems designed for ease of use.
336 questions
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
852 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tanay Prasad 2,115 Reputation points
    2023-08-02T07:05:18.5+00:00

    Try running this code-

    Private Sub GetUmFile()
        ' ... Your existing code ...
    
        strSQL = "DELETE FROM tblHTSAudit WHERE [ITEM NO] Is Null;"
        DoCmd.SetWarnings False
        DoCmd.RunSQL strSQL
        DoCmd.SetWarnings True
    
        ' ... Your existing code ...
        
        Dim rs As DAO.Recordset
        Set rs = CurrentDb.OpenRecordset("Select * From tblHTSAudit")
        If Not rs.EOF And Not rs.BOF Then
            rs.MoveFirst
            
            While (Not rs.EOF)
                ' ... Your existing code ...
    
                If rs.Fields("BUSINESS UNIT") <> "Hussmann" And rs.Fields("BUSINESS UNIT") <> "Commercial Insulating Glass" And rs.Fields("BUSINESS UNIT") <> "Commercial Refrigerator Door" Then
                    ' ... Your existing code ...
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL sql
                    DoCmd.SetWarnings True
                End If
                
                ' ... Your existing code ...
    
                If IsNull(DLookup("HTSUS", "_USHTS", "HTSUS = '" & rs.Fields("HTSUS") & "'")) Then
                    ' ... Your existing code ...
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL sql
                    DoCmd.SetWarnings True
                End If
    
                ' ... Your existing code ...
    
                If IsNull(DLookup("ECCN", "dbo_ECCN", "ECCN = '" & rs.Fields("ECCN") & "'")) Then
                    ' ... Your existing code ...
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL sql
                    DoCmd.SetWarnings True
                End If
    
                ' ... Your existing code ...
                rs.MoveNext
            Wend
        End If
        rs.Close
    
        ' ... Your existing code ...
        MsgBox "Done"
    End Sub