SQL查询无法正常工作-使用Where条件不匹配

时间:2019-02-06 15:15:06

标签: sql excel ms-access

我正在尝试将一个数据库连接到excel。

当表在没有任何条件的情况下与之链接时,效果很好。 当我尝试放置WHERE条件时,出现类型不匹配错误。

Where Data.`InfoCreation Date`>= ?

在访问时,该字段正在使用日期/时间作为数据类型,它看起来像:

InfoCreation Date
18/12/2018 05:49:00

我正在尝试在Excel中匹配日期格式类型为18/12/2018

我想要的是选择一个所选日期之前的所有日期。

有人可以帮我吗? 谢谢

1 个答案:

答案 0 :(得分:0)

您需要将字符串转换为日期。为此,您可以使用the msaccess FORMAT() function

Option Explicit

Public Sub DeleteEmpty()
    Dim wsInput As Worksheet 'define worksheet
    Set wsInput = ThisWorkbook.Worksheets("Input")

    Dim FirstRow As Long, LastRow As Long

    On Error Resume Next 'Next line throws error if  "Revenue" or "Total Revenue" is not found
    FirstRow = Application.WorksheetFunction.Match("Revenue", wsInput.Range("A:A"), False) + 1
    LastRow = Application.WorksheetFunction.Match("Total Revenue", wsInput.Range("A:A"), False) - 1
    On Error GoTo 0 'Always re-activate error handling!

    'Check if both "Revenue" and "Total Revenue" were found
    If FirstRow = 0 Or LastRow = 0 Then
        MsgBox "Revenue or Total Revenue not found"
        Exit Sub
    End If

    'Find empty cells in column J between FirstRow (Revenue) and LastRow (Total Revenue)
    Dim EmptyCellsInJ As Range
    On Error Resume Next
    Set EmptyCellsInJ = wsInput.Range(wsInput.Cells(FirstRow, "J"), wsInput.Cells(LastRow, "J")).SpecialCells(xlCellTypeBlanks)
    On Error GoTo 0

    'If there are empty cells delete their rows
    If Not EmptyCellsInJ Is Nothing Then
        EmptyCellsInJ.EntireRow.Delete
    Else
        MsgBox "nothing to delete"
    End If
End Sub