如何通过宏检查是否有适合参数的数据

问题描述 投票:-1回答:1

我想检查一下我的数据是否符合用户输入我的宏的月份和年份,以便我知道要查询哪个查询,我该怎么做?我的代码到目前为止:

Sub macro1()
    Dim year As Integer
    Dim month As Integer
    year = InputBox("What year would you want to get data from?")
    month = InputBox("What month would you want to get data from")
End Sub
ms-access access-vba
1个回答
0
投票

你可以使用DLookup:

Dim DataExists As Boolean

If Not IsNull(DLookup("[SomeField]", "[YourTable]", "DateDiff('m', [YourDateField], DateSerial(" & year & ", " & month & ", 1)) = 0") Then
    DataExists = True
End If
© www.soinside.com 2019 - 2024. All rights reserved.