As a side note, I had this coded a different way (on the combo boxes themselves instead of on the form before update) and did not have the problem mentioned above (regarding editing prices, etc.) Below is the code I used and it would notify you immediately when you changed the prefix, style number, or suffix, but the main problem here is that it gives the error, but can save the record anyway, PLUS when selecting the info for the product code it would give false errors (for instance if I already had a product code "WC 402" with no suffix--because most products actually do not require a suffix-- and needed to add "WC 402 HR"...when I selected the prefix "WC" and the style number "402" it would give the error without giving me a chance to select the suffix "HR"....not to mention this code is bulky...
Code:
Private Sub Prefix_AfterUpdate()
On Error GoTo Err_Exit_this_sub
Dim x As Variant
x = DLookup("[Product_Code]", "[tbl_Products]", "[Product_Code]='" & [Forms]![frm_Products]![Product_Code] & "'")
If Not IsNull(x) Then
Beep
MsgBox "That value already exists", vbOKOnly, "Duplicate Value"
Cancel = True
[Forms]![frm_Products]![Prefix] = ""
[Forms]![frm_Products]![Style_Number] = ""
[Forms]![frm_Products]![Suffix] = " "
End If
Exit_this_sub:
Exit Sub
Err_Exit_this_sub:
MsgBox Error$
Resume Exit_this_sub
End Sub
Private Sub Style_Number_AfterUpdate()
On Error GoTo Err_Exit_this_sub
Dim x As Variant
x = DLookup("[Product_Code]", "[tbl_Products]", "[Product_Code]='" & [Forms]![frm_Products]![Product_Code] & "'")
If Not IsNull(x) Then
Beep
MsgBox "That value already exists", vbOKOnly, "Duplicate Value"
Cancel = True
[Forms]![frm_Products]![Prefix] = ""
[Forms]![frm_Products]![Style_Number] = ""
[Forms]![frm_Products]![Suffix] = " "
End If
Exit_this_sub:
Exit Sub
Err_Exit_this_sub:
MsgBox Error$
Resume Exit_this_sub
End Sub
Private Sub Suffix_AfterUpdate()
On Error GoTo Err_Exit_this_sub
Dim x As Variant
x = DLookup("[Product_Code]", "[tbl_Products]", "[Product_Code]='" & [Forms]![frm_Products]![Product_Code] & "'")
If Not IsNull(x) Then
Beep
MsgBox "That value already exists", vbOKOnly, "Duplicate Value"
Cancel = True
[Forms]![frm_Products]![Prefix] = ""
[Forms]![frm_Products]![Style_Number] = ""
[Forms]![frm_Products]![Suffix] = " "
End If
Exit_this_sub:
Exit Sub
Err_Exit_this_sub:
MsgBox Error$
Resume Exit_this_sub
End Sub