Discontinue is true (1 Viewer)

hfsitumo2001

Member
Local time
Today, 12:16
Joined
Jan 17, 2021
Messages
365
Hello, if the item of the inventory, is there any global function/module that in any form we can not enter data for the item?
Thanks for any help
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:16
Joined
Feb 28, 2001
Messages
27,175
In general, any time you want to do something like "disallow entry" because the item should be blocked,
1) there has to be a usable indicator that it is blocked
2) EVERY form that could possibly be used to enter the data would have to check for the item's status and take appropriate action.

So SUPPOSE that you have a Yes/No field called Discontinued and suppose that each item whether active or not has a unique identifying value. (If it is an inventory, something we commonly call an SKU could be such a value.)

If the form has a field where manual data entry is required, then to do that entry the field must have focus. Which means when you are about to add data related to that item, you have to tab out to the next control or click directly into another control. Which means that the control where you entered this hypothetical SKU will experience a controlname_LostFocus event.

In that _LostFocus event code, you can use code similar to

Code:
IsDiscontinued = DLookup( "[Discontinued]", "inventorytable", "[SKU]=" & Me.SKU )
If CBool( IsDiscontinued ) Then
    do something to disallow the operation
Else
    do something to continue the operation
End If

The other place is in the Form_BeforeUpdate event, where you would again have something to trap the discontinued item. If you test this in the Form_BeforeUpdate event, you can pass back a Cancel parameter as TRUE to cancel the update.

There is no simple solution for your question because the basis for rejecting the value requires a lookup of the Yes/No field. However, it is easy to look up the flag and then act on it.
 

Ranman256

Well-known member
Local time
Today, 15:16
Joined
Apr 9, 2015
Messages
4,337
Lock the form and data cannot be entered:

Dim bAllow as Boolean
BAllow =not dlookup("[discontinue]","table",....)
Me.allowedits = bAllow
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 20:16
Joined
Sep 12, 2006
Messages
15,653
One issue might be that if you disallow edits on a form, as well as locking all the bound controls, you might find you can't change interactive selection boxes to filter the form and so on. Worth testing.
 

Users who are viewing this thread

Top Bottom