M
mscertified
I have to do what I thought would be a simple task.
I have a continuous form that maintains a table containing one column.
I need to trap 3 possible errors.
(1) Records cannot be deleted if they are used in another table
(2) Records cannot be inserted if it would create a duplicate name
(3) Records cannot be renamed if it would create a duplicate name
I'm using the BeforeInsert, BeforeDelete and BeforeUpdate events (with
DLookups)to check these conditions. However, I keep getting a message 'you
cancelled the previous operation'. I have no idea what this means and Help
did not help me. Here is the code:
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim X As Variant
X = DLookup("TechAssigned", "tblTechAssigned", "TechAssigned='" &
Me.TechAssigned & "'")
If Not IsNull(X) Then
MsgBox "Cannot add team with a name already in list", , "Duplicate team"
Cancel = 1
Exit Sub
End If
Cancel = 0
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim X As Variant
X = DLookup("TicketNo", "tblCSTickets", "LastAssignedTo='" &
Me.TechAssigned.OldValue & "'")
If Not IsNull(X) Then
MsgBox "Cannot rename team - used by a ticket", , "In use"
Cancel = 1
Exit Sub
End If
X = DLookup("TechAssigned", "tblTechAssigned", "TechAssigned='" &
Me.TechAssigned & "'")
If Not IsNull(X) Then
MsgBox "Cannot rename team to a name already in list", , "Duplicate
team"
Cancel = 1
Exit Sub
End If
Cancel = 0
End Sub
Private Sub Form_Delete(Cancel As Integer)
Dim X As Variant
X = DLookup("LastAssignedTo", "tblCSTickets", "LastAssigned='" &
Me.TechAssigned & "'")
If Not IsNull(X) Then
MsgBox "Cannot delete team - used by a ticket", , "In use"
Cancel = 1
Exit Sub
End If
Cancel = 0
End Sub
I have a continuous form that maintains a table containing one column.
I need to trap 3 possible errors.
(1) Records cannot be deleted if they are used in another table
(2) Records cannot be inserted if it would create a duplicate name
(3) Records cannot be renamed if it would create a duplicate name
I'm using the BeforeInsert, BeforeDelete and BeforeUpdate events (with
DLookups)to check these conditions. However, I keep getting a message 'you
cancelled the previous operation'. I have no idea what this means and Help
did not help me. Here is the code:
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim X As Variant
X = DLookup("TechAssigned", "tblTechAssigned", "TechAssigned='" &
Me.TechAssigned & "'")
If Not IsNull(X) Then
MsgBox "Cannot add team with a name already in list", , "Duplicate team"
Cancel = 1
Exit Sub
End If
Cancel = 0
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim X As Variant
X = DLookup("TicketNo", "tblCSTickets", "LastAssignedTo='" &
Me.TechAssigned.OldValue & "'")
If Not IsNull(X) Then
MsgBox "Cannot rename team - used by a ticket", , "In use"
Cancel = 1
Exit Sub
End If
X = DLookup("TechAssigned", "tblTechAssigned", "TechAssigned='" &
Me.TechAssigned & "'")
If Not IsNull(X) Then
MsgBox "Cannot rename team to a name already in list", , "Duplicate
team"
Cancel = 1
Exit Sub
End If
Cancel = 0
End Sub
Private Sub Form_Delete(Cancel As Integer)
Dim X As Variant
X = DLookup("LastAssignedTo", "tblCSTickets", "LastAssigned='" &
Me.TechAssigned & "'")
If Not IsNull(X) Then
MsgBox "Cannot delete team - used by a ticket", , "In use"
Cancel = 1
Exit Sub
End If
Cancel = 0
End Sub