473,387 Members | 1,693 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,387 software developers and data experts.

Update syntax

N J
Hi,

I have code below that is used to add a new number to the txtTracking Field
based on what the user puts into the text box (txtTracking). What I would
like it to do is add whatever is already in the OnHand field, to what the
user has put into the txtTracking text box, to replace the number in OnHand

So ... OnHand = 20, user inputs 15 and the event is run, OnHand value is now
35
Any help would be greatly appreciated, thank you.
Private Sub cmdOK_Click()
Dim strsql As String

CurrentDb.Execute "Update tblStock Set OnHand = """ & Me.txtTracking & """
Where SKU = " & Me.txtOrderNumber & ";", dbfailonerror
Me.StatusListBox.AddItem "STOCK # " & Me.txtOrderNumber & " MARKED DOWN QTY
OF " & Me.txtTracking & "", 0
txtOrderNumber.SetFocus
End Sub

--

Kind Regards,
Customer Services,
Blue Lagoon Products
http://www.fastminimoto.co.uk
P.S. For us to answer your emails efficiently, please always include the
original message. Thank you.
Nov 16 '05 #1
2 5159
You need to query for the first value, add it to the second, and then
run your update command. You can accomplish this in a couple of ways.

1) Have OnHand appear in a textbox in the Form somewhere (you can make
this invisible) and then it would be (assuming the name of the text box
is txtOnHand:

Private Sub cmdOK_Click()
Dim strsql As String
Dim iNewOnHand as Integer

iNewOnHand = Me.txtOnHand.Value + Me.txtTracking.Value

CurrentDb.Execute "Update tblStock Set OnHand = """ & iNewOnHand & """
Where SKU = " & Me.txtOrderNumber & ";", dbfailonerror
Me.StatusListBox.AddItem "STOCK # " & Me.txtOrderNumber & " MARKED DOWN
QTY
OF " & Me.txtTracking & "", 0
txtOrderNumber.SetFocus
End Sub

2) Or the other way to do it would be to query for it in the code,
then add it, then update it:

Private Sub cmdOK_Click()
Dim oRs as ADODB.Recordset
Dim oConn as ADODB.Connection
Set oRs = New ADODB.Recordset
Set oConn = CurrentProject.Connection
Dim strsql As String
Dim iOnHandTotal as Integer

strsql = "SELECT OnHand FROM tblStock Where SKU = " & Me.txtOrderNumber
& ";"

oRs.Open strsql, oConn

iOnHandTotal = oRs("OnHand") + Me.txtTracking

CurrentDb.Execute "Update tblStock Set OnHand = """ & iOnHandTotal &
"""
Where SKU = " & Me.txtOrderNumber & ";", dbfailonerror
Me.StatusListBox.AddItem "STOCK # " & Me.txtOrderNumber & " MARKED DOWN
QTY
OF " & Me.txtTracking & "", 0
txtOrderNumber.SetFocus

oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing

End Sub

Hope this helps.

JK

Nov 16 '05 #2
You are 99.9% there. Just change your sql statement a tiny bit.
CurrentDb.Execute "Update tblStock Set OnHand = OnHand+""" &
Me.txtTracking & """ etc.
HTH
Pachydermitis

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
14
by: bolidev | last post by:
I'm new to SQL and can't figure out how to update my table (StoreItemStatus) that contains the current status for items in each store (STORE_KEY, ITEM_KEY, STATUS,...). I get updated status info...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
6
by: HeadScratcher | last post by:
I am trying to speed up my update statements by removing inner select statements. Example: update orders set shipname = (select contactName from customers where customerid = orders.customerID)...
3
by: Jerry | last post by:
Well, here is some weirdness. First, I noticed that I have 2 Set keywords (silly me). so I removed the 2nd "Set" but still got a syntax error. Then I removed the Where clause, and now it works...
5
by: Al | last post by:
Hi, I need to update tables in access 97. The table names have spaces (not my choice). My update fails even though I use the OleDbCommandBuilder. Here is a code I am using myDataAdapter = New...
9
by: zMisc | last post by:
When I try to update record, I kept getting this error: Row cannot be located for updating. Some values may have been changed since it was last read. No other users are accessing the database...
2
by: WU | last post by:
Hallo, mir ist die Update Syntax im SQL bekannt aber für das was ich möchte, reicht mein wissen leider nicht aus. Habe 2 Tabellen mit folgenden Feldern 1. Tabelle: LaufendeNr, Datum 2....
2
by: explode | last post by:
I made nova oledbdataadapter select update insert and delete command and connection veza. dataset is Studenti1data, I made it by the new data source wizard,and made datagridview and bindingsource...
1
by: sibusiso | last post by:
HI Can Any one help I have extra field on a table like FDate, FYear, FMonth, FDay, FDatename I have a triger that I will update this field every time transaction hapened, this field must...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.