By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,480 Members | 2,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,480 IT Pros & Developers. It's quick & easy.

no qtyOnHand update if not a new record

P: n/a
there is a quantity update on lost focus even of the text box i.e. it
update quantity when it lost focus. Now I want this even work only if I

click in this text box or if entring a new record. Any one know how to
do that.

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"click in this text box"
You could maybe use the OnClick or On Got Focus events.

"if entering a new record"
If you view properties for the form there is a After Insert and Before
Insert event related to inserting new records. I'm not sure if they
are fired when the person hits the add record button or if they are
fired when the user finishes entering data and leaves focus of that
record. I would put some debuggin statements in there to explore the
behavior of these events.

I should point out that your above post is hard to read, at least for
me, and I'm not absolutely sure what specifically you're asking.
Please don't be offended, but you might get more help if you try to
rephrase your statement, or maybe try to find a message board in your
native language.

Nov 13 '05 #2

P: n/a
this is my code, it is updating QTY on Hand when you make a new sale or
if you got some product returned. Now as it is updating QTY when qty
textbox lost focus if some one is going through records and whenever
this qty text box will losee focus it will be fired and change the
quantity in the product table. I want it, to be fired only ig user
clicks qty text box or only if new record is inserted.Can you help.
Private Sub qty_Click()
On Error GoTo Err_qty_Click
Dim TotalQty As Integer
TotalQty = 0
Product = Forms![frmSale]![tblSaleDetail]![Product]

TotalQty = DLookup("[QtyOnHand]", "[Products]", "[ProductID]=" &
Product)
If (TotalQty - [qty]) < 1 Then
MsgBox "Inventory Below 0. Quantity Issued is To High!"

Exit Sub
End If
TotalQty = TotalQty + [qty]
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE [Products] SET " & _
" [Products].[QtyOnHand] = " & TotalQty & _
" WHERE [Products].[ProductID] =" & [Product]
DoCmd.SetWarnings True
Exit_qty_Click:
Exit Sub

Err_qty_Click:
MsgBox Err.Description
Resume Exit_qty_Click
End Sub

Private Sub qty_LostFocus()
On Error GoTo Err_qty_LostFocus
Dim TotalQty As Integer
TotalQty = 0
Product = Forms![frmSale]![tblSaleDetail]![Product]

TotalQty = DLookup("[QtyOnHand]", "[Products]", "[ProductID]=" &
Product)

If (TotalQty - [qty]) < 1 Then
MsgBox "Inventory Below 0. Quantity Issued is To High!"

Exit Sub
End If
TotalQty = TotalQty - [qty]
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE [Products] SET " & _
" [Products].[QtyOnHand] = " & TotalQty & _
" WHERE [Products].[ProductID] =" & [Product]
DoCmd.SetWarnings True
Me.subtotal = Me.qty * Me.SalePrice
Exit_qty_LostFocus:
Exit Sub

Err_qty_LostFocus:
MsgBox Err.Description
Resume Exit_qty_LostFocus
End Sub

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.