Adam McReynolds
Registered User.
- Local time
- Today, 15:21
- Joined
- Aug 6, 2012
- Messages
- 129
My code won't recognize my cases using "Left" but it fires on the "Case Else" options. What am I missing? Second, any suggestions to make this code shorter?
This code is firing on a Serial Number Field in a datasheet form.
This code is firing on a Serial Number Field in a datasheet form.
Code:
Private Sub Incoming_Module_Sn_AfterUpdate()
Dim warrantyCheck As Date
Select Case Me.customer
''''''CASE ALPHA CUSTOMER
Case "Alpha"
Select Case Me.end_user
Case Left(Me.end_user, 2) = "TW"
'BEG 6 MONTHS ''''''''''''''''''''''''''''''''''''
If Me.Incoming_Disposition = "Estimate" Then
If Not IsNull(DLookup("Incoming_Module_Sn", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "'")) Then
If IsNull(DMax("[complete_date]", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "'")) Then
MsgBox "No Complete date found", vbOKOnly + vbCritical
Exit Sub
Else
warrantyCheck = DMax("[complete_date]", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "' And [Incoming_Disposition] = 'Completed'")
If Date - warrantyCheck < 190 Then ' approx 183 + 7 (6 months + a week)
If MsgBox("This unit is still under warranty and was last completed on " & warrantyCheck & ". Would you like to mark this as a warranty?", vbYesNo, "Duplicate Warning") = vbYes Then
Me.Incoming_Disposition = "Warranty"
End If
End If
End If
End If
End If
'END 6 MONTHS'''''''''''''''''''''''''''''''''''''''''''''
Case Left(Me.end_user, 4) = "Char"
' BEG 1 YEAR''''''''''''''''''''''''''''''''''''
If Me.Incoming_Disposition = "Estimate" Then
If Not IsNull(DLookup("Incoming_Module_Sn", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "'")) Then
If IsNull(DMax("[complete_date]", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "'")) Then
MsgBox "No Complete date found", vbOKOnly + vbCritical
Exit Sub
Else
warrantyCheck = DMax("[complete_date]", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "' And [Incoming_Disposition] = 'Completed'")
If Date - warrantyCheck < 372 Then ' approx 365 + 7 (1 Year + a week)
If MsgBox("This unit is still under warranty and was last completed on " & warrantyCheck & ". Would you like to mark this as a warranty?", vbYesNo, "Duplicate Warning") = vbYes Then
Me.Incoming_Disposition = "Warranty"
End If
End If
End If
End If
End If
'END 1 YEAR'''''''''''''''''''''''''''''''''''''''''''''
Case Else
'BEG 6 MONTHS''''''''''''''''''''''''''''''''''''
If Me.Incoming_Disposition = "Estimate" Then
If Not IsNull(DLookup("Incoming_Module_Sn", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "'")) Then
If IsNull(DMax("[complete_date]", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "'")) Then
MsgBox "No Complete date found", vbOKOnly + vbCritical
Exit Sub
Else
warrantyCheck = DMax("[complete_date]", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "' And [Incoming_Disposition] = 'Completed'")
If Date - warrantyCheck < 190 Then ' approx 183 + 7 (6 months + a week)
If MsgBox("This unit is still under warranty and was last completed on " & warrantyCheck & ". Would you like to mark this as a warranty?", vbYesNo, "Duplicate Warning") = vbYes Then
Me.Incoming_Disposition = "Warranty"
End If
End If
End If
End If
End If
'END 6 MONTHS'''''''''''''''''''''''''''''''''''''''''''''
End Select
''''''CASE COX CUSTOMER
Case Left(Me.customer, 3) = Cox
' BEG 1 YEAR''''''''''''''''''''''''''''''''''''
If Me.Incoming_Disposition = "Estimate" Then
If Not IsNull(DLookup("Incoming_Module_Sn", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "'")) Then
If IsNull(DMax("[complete_date]", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "'")) Then
MsgBox "No Complete date found", vbOKOnly + vbCritical
Exit Sub
Else
warrantyCheck = DMax("[complete_date]", "tbl_Module_Repairs", "Incoming_Module_Sn = '" & Me.Incoming_Module_Sn.Text & "' And [Incoming_Disposition] = 'Completed'")
If Date - warrantyCheck < 372 Then ' approx 365 + 7 (6 months + a week)
If MsgBox("This unit is still under warranty and was last completed on " & warrantyCheck & ". Would you like to mark this as a warranty?", vbYesNo, "Duplicate Warning") = vbYes Then
Me.Incoming_Disposition = "Warranty"
End If
End If
End If
End If
End If
'END 1 YEAR'''''''''''''''''''''''''''''''''''''''''''''
Case Else
If Nz(DCount("incoming_module_sn", "tbl_Module_Repairs", " incoming_module_sn = '" & Me.Incoming_Module_Sn.Text & "'"), 0) > 0 Then
If MsgBox("The Serial Number already exists. Check Warranty! Verify the warranty period for this customer. Do you wish to continue?", vbOKCancel, "Duplicate Warning") = vbCancel Then
Cancel = True
Me.Undo
Exit Sub
End If
End If
End Select
End Sub