I beleive I am getting close now, Am getting a mismatch error... So I dont have it quite correct?
Any Thoughts?
Code Below....
Code:
Private Sub SystemCategoryName_BeforeUpdate(Cancel As Integer)
Dim IT As String
Dim TGT As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Dim ITkey As Long
Dim TGTkey As Long
On Error GoTo Err_Handler
Set rsc = Me.RecordsetClone
IT = Nz(Me.SystemCategoryName, "")
TGT = Nz(Me.SystemCategoryTypeID, "")
ITkey = Nz(DLookup("SystemCategoryID", "tblSystemCategory", "SystemCategoryName=" & "'" & IT & "'"), 0)
TGTkey = Nz(DLookup("SystemCategoryTypeID", "tblSystemCategory", "SystemCategoryTypeID=" & "'" & TGT & "'"), 0)
'does not exist, add record
If ITkey = 0 And TGTkey = TGT Then
Exit Sub
End If
'if exist sting, then don't add
If ITkey > 0 And TGTkey = TGT Then
Me.Undo
'Cancel = True
MsgBox "This Category Value has all ready been entered"
Exit Sub
End If
Exit_Handler:
Exit Sub
Err_Handler:
Select Case Err
Case Else
MsgBox "Error " & Err & ": " & Error$, vbExclamation, "SystemCategoryName_BeforeUpdate(Cancel As Integer)"
Resume Exit_Handler
End Select
If Not Me.NewRecord And SystemValue Then
If MsgBox("This is a SYSTEM VALUE. Are you SURE you want to change it?", vbYesNoCancel) <> vbYes Then
Cancel = True
Undo
Modified = Now()
Exit Sub
End If
End If
End Sub