在 Access 数据库 Visual Basic 代码中获取 2 年前的日期

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

我的access数据库文件中有一些代码,它是用Visual Basic编写的,我想要从下面的代码中得到的是,我想要得到#1/,而不是“#1/1/2020#”的硬编码值/12023#今年,意味着两年前的第一天,你能帮我一下吗,非常感谢。

Private Sub txt_bene_birth_date_BeforeUpdate(Cancel As Integer)
Dim s As String

    If IsNull(txt_bene_birth_date) Then
        s = "The beneficiary birthdate field is a required field and can not be left blank." & vbCrLf & vbCrLf & vbCrLf
        InputError txt_bene_birth_date, s, "Beneficiary Birthdate"
        Exit Sub
    End If
    
    If Not IsNull(txt_bene_birth_date) And (txt_bene_birth_date < #1/1/1900# Or txt_bene_birth_date > #1/1/2020#) Then
        s = "The calculator does not support beneficiary birthdates prior to 1/1/1900 or subsequent to 1/1/2020.  " & vbCrLf & vbCrLf & vbCrLf
        InputError txt_bene_birth_date, s, "Beneficiary Birthdate"
        Exit Sub
    End If
    
End Sub
ms-access vb6
1个回答
0
投票

类似这样的:

txt_bene_birth_date > #01/01/ & DatePart("yyyy",Today())-2 & #

© www.soinside.com 2019 - 2024. All rights reserved.