I have a table that stores the status of various pieces of hardware. I need to prevent the user from entering duplicate serial numbers so I decided to use DCount...
1. I have created a query called qryExistingSN that contains requires criteria from a subform.
PartInvId
[Forms]![sbfPartsInventory_PS]![PartInvId]
SerialNumber
[Forms]![sbfPartsInventory_PS]![SerialNumber]
2. My subform called sbfPartInventory_PS resides on a 'PartStatus' page on a main form called 'frmPartInventory'. The subform container is called sbfPartInventory.
3. On the subform, in the After Update event of the SerialNumber field I have the following code
If DCount("[SerialNumber]", _
"qryExistingSN", _
"[PartInvId] = '" & Forms![frmPartInventory].[sbfPartsInventory].Form.[PartInvId] & "' And " & _
"[SerialNumber] = '" & Forms![frmPartInventory].[sbfPartsInventory].Form.[SerialNumber] & "'") > 0 Then
MsgBox "this serial number already exists. Please try again.", vbCritical, "Warning!"
Me.Undo
End If
I keep getting a runtime error '2001' You have canceled the previous operation. I think it may be a syntax error in that I'm not referencing PartInvId or SerialNumber correctly... ??????
I have tried
Forms!frmPartInventory!sbfPartsInventory_PS!PartInvId
and that will not work either...
Any ideas on how I can solve this?
Thanks!
1. I have created a query called qryExistingSN that contains requires criteria from a subform.
PartInvId
[Forms]![sbfPartsInventory_PS]![PartInvId]
SerialNumber
[Forms]![sbfPartsInventory_PS]![SerialNumber]
2. My subform called sbfPartInventory_PS resides on a 'PartStatus' page on a main form called 'frmPartInventory'. The subform container is called sbfPartInventory.
3. On the subform, in the After Update event of the SerialNumber field I have the following code
If DCount("[SerialNumber]", _
"qryExistingSN", _
"[PartInvId] = '" & Forms![frmPartInventory].[sbfPartsInventory].Form.[PartInvId] & "' And " & _
"[SerialNumber] = '" & Forms![frmPartInventory].[sbfPartsInventory].Form.[SerialNumber] & "'") > 0 Then
MsgBox "this serial number already exists. Please try again.", vbCritical, "Warning!"
Me.Undo
End If
I keep getting a runtime error '2001' You have canceled the previous operation. I think it may be a syntax error in that I'm not referencing PartInvId or SerialNumber correctly... ??????
I have tried
Forms!frmPartInventory!sbfPartsInventory_PS!PartInvId
and that will not work either...
Any ideas on how I can solve this?
Thanks!
Attachments
Last edited: