使用表格检查某人是否超过给定年龄

时间:2013-04-16 06:12:58

标签: forms vba ms-access

我已经尝试过此代码,以便让我的表格告诉我,如果客户是在考虑雇用R16或R18电影,是否年龄超过16或18岁。

HireMovieID和HireCustomerID是我表单上的两个文本框。 MovieID和CustomerID是我的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电影,它会说所有客户都太年轻而无法雇佣它吗?我该如何解决这个问题?

提前感谢您的帮助! :)

0 个答案:

没有答案