I am new at VB, I am trying to solve the following problem and I would really appreciate any help.
I have a form with several fields. Two of these fields automatically calculate the remaining items in inventory as items are being removed.
If the number of items that I remove is more than the number of items I currently have in inventory, a Text Box Field automatically displays the message:
"the amount you are trying to remove is higher than the amount you have”
If the number of items that I remove is LESS than the number of items I currently have in inventory, the Text Box Field does NOT display the message.
Question: What I am trying to do is prevent anyone from closing the FORM when they click on the “close form icon” if the Text Box Field is displaying the message, and ONLY allow the user to close this form if the message is not display. Is this possible.
An Access form has a CloseButton property. If you set this property to False (or zero), the close button in the System menu (ControlBox, in the upper right corner) of the form will not be available. Unfortunately you can only define this property in Design view, so:
If <Condition> Me.CloseButton = True Else Me.CloseButton = False
will not work, it must be defined once for all.
You can also set the Cancel parameter to True in the Form_Unload event:
Private Sub Form_Unload(Cancel As Integer)
If <Condition> Then Cancel = True
But I cannot know what consequences this can have in your application, it depends on how the form is built and which code it contains.