Hello All,
I'm using the code below to verify if a Product Number has already been entered into the form.
I'm having trouble, however, adapting it to three primary key fields. For example, I need to verify if the same "Product#", "Description" and "Colour" has already been entered - not only the "Product#".
Thanks, in advance, for all your help.
I'm using the code below to verify if a Product Number has already been entered into the form.
Private Sub ProductID_BeforeUpdate(Cancel As Integer)
Dim varX As Variant
varX = DLookup("[ProductID]", "tblProducts", "[ProductID] = '" & Forms!frmProducts.[ProductID] & "'")
If Not IsNull(varX) Then
MsgBox [ProductID].Value & " already exists as a product number!"
Me.Undo
Cancel = True
Me.Recordset.FindFirst "ProductID='" & varX & "'"
Else
'do nothing!
End If
End Sub
Dim varX As Variant
varX = DLookup("[ProductID]", "tblProducts", "[ProductID] = '" & Forms!frmProducts.[ProductID] & "'")
If Not IsNull(varX) Then
MsgBox [ProductID].Value & " already exists as a product number!"
Me.Undo
Cancel = True
Me.Recordset.FindFirst "ProductID='" & varX & "'"
Else
'do nothing!
End If
End Sub
I'm having trouble, however, adapting it to three primary key fields. For example, I need to verify if the same "Product#", "Description" and "Colour" has already been entered - not only the "Product#".
Thanks, in advance, for all your help.