我已经尝试过这段代码,以便让我的表格告诉我,如果客户想租用 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 电影,它会说所有的客户都太年轻而不能雇用它?我怎样才能解决这个问题?
在此先感谢您的帮助!:)