473,320 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

no qtyOnHand update if not a new record

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
2 1223
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I...
3
by: Fred | last post by:
Hi out there, I have problems finding a way to warn a user that another user intends soon to update the same specific row. Let me explain. User 1 get to a JSP "update customer record" page....
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
3
by: khan | last post by:
I want QTY on hand to be updated when record in detail sale is deleted. can any one help
3
by: Mihaly | last post by:
I want to update a record into a table in SQL Server 2000 database from C#. This table is used concurently for other users too, and I want to be sure that from the read of record to the update no...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
3
by: PAUL | last post by:
Hello, I have 2 datasets I am trying to update. The parent table seems to update fine but when I go update the chiled table I get an error message that says I need a related record in the parent...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.