I want to do the above, where the control is OrderStatus and it's default is Awaiting Approval
OrderStatus has 2 values, Awaiting Approval and Allocated
If the records Status are NOT set to Allocated, then proceed with code,else do nothing. I want to skip all the records where the status is already set to Allocated.
I guess I am having a brain fart, can't think. Here is the complete code that runs when the command button is clicked.
'DoCmd.RunCommand acCmdSelectAllRecords
'If [OrderStatus] = "Awaiting Approval" Then ' Here is where my brain stops.
Dim AddItemsAsInventorymsgbox As String
If Me!OrderStatus = "Allocated" Then 'Checks if Order has been Posted already.
MsgBox "Order Has Already Been Posted"
Exit Sub
End If
AddItemsAsInventorymsgbox = MsgBox("Do you want to Allocate these items to inventory? This is non reversible", vbInformation + vbYesNo, "OrderDetailsSubform")
If (AddItemsAsInventorymsgbox = vbYes) Then
DoCmd.SetWarnings False
If Me.NewRecord Then 'Subtract From Inventory
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Products", dbOpenTable)
rst.Index = "PrimaryKey"
rst.Seek "=", Me!ProductID
rst.Edit
rst("Inventory") = rst("Inventory") - Me!Quantity ' Subtracts items from Inventory
rst("Sold") = rst("Sold") + Me!Quantity 'Adds items to Sold quantity
rst.Update
rst.Close
Set rst = Nothing
Set dbs = Nothing
End If
Me.[OrderStatus] = "Allocated"
DoCmd.SetWarnings True
DoCmd.Save
If Me.Dirty Then Me.Dirty = False 'Forces a Save Record.
End If