Forms 使用表格检查某人是否比给定年龄大

Forms 使用表格检查某人是否比给定年龄大,forms,vba,ms-access,Forms,Vba,Ms Access,我尝试了这段代码,以便让我的表单告诉我,如果客户试图租用R16或R18电影,他们的年龄是16岁还是18岁 HireMovieID和HireCustomerID是我表单上的两个文本框。MovieID和CustomerID是my MovieList和CustomerInfo表中的列 Private Sub HireCommand_Click() If Not IsNumeric(HireMovieID) Or Not IsNumeric(HireCustomerID) Then M

我尝试了这段代码,以便让我的表单告诉我,如果客户试图租用R16或R18电影,他们的年龄是16岁还是18岁

HireMovieID和HireCustomerID是我表单上的两个文本框。MovieID和CustomerID是my MovieList和CustomerInfo表中的列

    Private Sub HireCommand_Click()

If Not IsNumeric(HireMovieID) Or Not IsNumeric(HireCustomerID) Then
    MsgBox "Error: Not a number"
    Exit Sub
End If

Dim MovieRating As String
Dim CustomerDOB As Date
Dim Age16Check As Date
Dim Age18Check As Date

MovieRating = DLookup("[Rating]", "MovieList", "MovieID = [Forms]![HireForm]![HireMovieID]")
CustomerDOB = DLookup("[DOB]", "CustomerInfo", "CustomerID = [Forms]![HireForm]![HireCustomerID]")
Age16Check = DateSerial(-16, Month(Date), Day(Date))
Age18Check = DateSerial(-18, Month(Date), Day(Date))


If MovieRating = "R16" Then
    If CustomerDOB > Age16Check Then
        MsgBox "This customer is too young to hire this movie"
    Else: MsgBox "This customer is old enough to hire this movie"
    End If
ElseIf MovieRating = "R18" Then
    If CustomerDOB > Age18Check Then
        MsgBox "This customer is too young to hire this movie"
    Else: MsgBox "This customer is old enough to hire this movie"
    End If
Else: MsgBox "This movie does not have a restricted rating, thus this customer may hire this DVD"
End If

End Sub
编辑:当我运行此代码时,如果我选择了一部R16电影,它会说所有的客户都太年轻了,无法租用它?我怎样才能解决这个问题


提前感谢您的帮助!:)

您的表单上是否有未绑定的电影ID和CustomerID控件?是的,这些是我的HireCustomerID和HireMovieID。