我想检查一下我的数据是否符合用户输入我的宏的月份和年份,以便我知道要查询哪个查询,我该怎么做?我的代码到目前为止:
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
你可以使用DLookup:
Dim DataExists As Boolean
If Not IsNull(DLookup("[SomeField]", "[YourTable]", "DateDiff('m', [YourDateField], DateSerial(" & year & ", " & month & ", 1)) = 0") Then
DataExists = True
End If