Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AfterUpdate Procedure....

Status
Not open for further replies.
Aug 17, 2000
23
US
I would like to subtract [quantity] from [stock]. If the
[quantity] is greater than [stock] a message is posted --
"Unable to complete order". I have this part complete.

How do I set [quantity] to focus and then if the amount
is valid. Subtract the [quantity] from [stock] This is
what I have so far....

Private Sub QUANTITY_AfterUpdate()
If [QUANTITY] > [STOCK] Then
MsgBox "UNABLE TO COMPLETE ORDER!"

Else

End If


End Sub
 
Private Sub QUANTITY_AfterUpdate()
If [QUANTITY] > [STOCK] Then
MsgBox "UNABLE TO COMPLETE ORDER!"
[Quantity].setfocus
Else
[Stock] = [Stock] - [Quantity]
[Quantity].setfocus
End If
End Sub

If I understand you correctly this should do it. I assumed that you wanted to also set the focus to [quanity] in both cases.

Bob Scriver
 
Bob Scriver,

Your suggestion works great! However, it doesn't
set the focus back to quantity when the Quantity
is greater than Stock. It starts a new record. I
have to move the cursor back to Quantity. Any
suggestiong would be appreciated!! Thanks...

 
Because the Object [Quantity] is the last TabStop object on your form it is dropping out the bottom of the list and creating a new record before you can set the focus back to the me![Quantity] object.

Open the Form property items. Change the Cycle property to Current Record. This keeps the cursor rotating through the current record and doesn't start a new record until you want it to. Now here is a little trick that I do in these situations. Create a small button on the form. You aren't going to click it or anything so it can be very small and you can place it off to the side away from everything so that the user doesn't inadvertenly click it. Change the buttons transparent property to Yes and the tabstop should be Yes also. Now paste your code that from the AfterUpdate procedure of me![Quantity] into the OnGotFocus event procedure of the transparent button. Select from the Menu Bar at the top View, then Tab Order. Move the transparent Button to the spot just below the object Quantity.

What will happen is that the analysis of the two form objects will take place when the focus moves to this transparent button. It will immediately analyze the Stock and Quantity fields, display the MsgBox, and return the focus to the Quantity object if Quantity is greater than Stock.

On the Else the Calculation will take place and you can Save the record and start a new one or just return the focus to an existing Object if you wish. I don't know how you are handling new records and such. You should be able to figure that out yourself.

I hope this solves you problem.

Bob Scriver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top