T
Tom
Hi all.
I have a table (tblStoreInv) with these fields: Index, Store, Product,
Quantity.
A form (SetInventory) that is connected to that table has these fields:
StoreID, Product, Squantity.
Only one record is allowed per store, product, Squantity.
So here is what I wrote:
Private Sub Squantity_BeforeUpdate(Cancel As Integer)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
strSQL = "SELECT [Quantity],[Store],[Product] FROM tblStoreInv WHERE
FORMS![SetInventory]![StoreID]=Store AND
FORMS![SetInventory]![Product]=Product AND
FORMS![SetInventory]![Squantity]=Quantity;"
Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
If rst.RecordCount > 0 Then ' duplicate entry
Cancel = True
MsgBox "Dupicate!"
Me.Undo
End If
Exit_Here:
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub
Private Sub Exit_Click()
DoCmd.Close
End Sub
It does not work.
Please help
TIA,
Tom
I have a table (tblStoreInv) with these fields: Index, Store, Product,
Quantity.
A form (SetInventory) that is connected to that table has these fields:
StoreID, Product, Squantity.
Only one record is allowed per store, product, Squantity.
So here is what I wrote:
Private Sub Squantity_BeforeUpdate(Cancel As Integer)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
strSQL = "SELECT [Quantity],[Store],[Product] FROM tblStoreInv WHERE
FORMS![SetInventory]![StoreID]=Store AND
FORMS![SetInventory]![Product]=Product AND
FORMS![SetInventory]![Squantity]=Quantity;"
Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
If rst.RecordCount > 0 Then ' duplicate entry
Cancel = True
MsgBox "Dupicate!"
Me.Undo
End If
Exit_Here:
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub
Private Sub Exit_Click()
DoCmd.Close
End Sub
It does not work.
Please help
TIA,
Tom