I am having problems validating entry data on my order entry screen. I have an Access front end to a MS SQL Server back end. The entry is simple. I have the following controls on a sub-form:
cboProductID (a combo box for available products), txtProductName (a text box for the name of the selected ID), Quantity (a text box for quantity of the selected product), Price (price of selected product) and LineTotal (quantity times price). I want to validate that a quantity is entered. I tried to use the control validation on the Access form for the Quantity text box stating ">0" as the Validation Rule and "You must enter a quantity" as the Validation Text. It is my understanding that you couldn't tab out of the control until the entry passes the validation rule. If I hit tab or enter, the cursor jumps to the next control, even though it didn't meet the validation criteria. I can't see that I am doing anything wrong.
I have also tried the following code in the LostFocus event:
This code generates the MsgBox message, but the cursor jumps to the next control when clicking OK on the message box, even though I have the SetFocus statement in the code.
I would like to get either of these options to work.
cboProductID (a combo box for available products), txtProductName (a text box for the name of the selected ID), Quantity (a text box for quantity of the selected product), Price (price of selected product) and LineTotal (quantity times price). I want to validate that a quantity is entered. I tried to use the control validation on the Access form for the Quantity text box stating ">0" as the Validation Rule and "You must enter a quantity" as the Validation Text. It is my understanding that you couldn't tab out of the control until the entry passes the validation rule. If I hit tab or enter, the cursor jumps to the next control, even though it didn't meet the validation criteria. I can't see that I am doing anything wrong.
I have also tried the following code in the LostFocus event:
Code:
If Me.Quantity = 0 Or IsNull(Me.Quantity) Then DoCmd.Beep MsgBox "You must enter a quantity.", vbOKOnly Me.Quantity.SetFocus GoTo Proc_Exit Else Forms![frmInvoiceOrders]!cmdSaveRec.Enabled = True End If
I would like to get either of these options to work.
Comment