473,412 Members | 2,142 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,412 software developers and data experts.

MS Access Form problem in update vba code

Hi,
I created a form using form wizard and placed a UPDATE button.
and written code

Expand|Select|Wrap|Line Numbers
  1. CurrentDb.Execute "UPDATE tblQuotation SET tblQuotation.ItemCategory = ItemCategory,tblQuotation.ItemDescription=ItemDescription,tblQuotation.FOBFactoryCost = FactoryCost WHERE tblQuotation.ItemNumber ='" & ItemNumber & "'"
I am updating value in FCost(textbox) and before clicking on update button the ELC(textbox) value which is calculated Field in Database Table is getting updated.

so please provide the solution how to handle asap.
Sep 25 '14 #1
2 1262
twinnyfo
3,653 Expert Mod 2GB
veeru8989,

For your Query:

Expand|Select|Wrap|Line Numbers
  1. UPDATE tblQuotation 
  2. SET tblQuotation.ItemCategory = ItemCategory, 
  3.     tblQuotation.ItemDescription = ItemDescription, 
  4.     tblQuotation.FOBFactoryCost = FactoryCost 
  5. WHERE tblQuotation.ItemNumber = '" & ItemNumber & "'"
Where are you getting the values for ItemCategory, ItemDescription and FactoryCost (lines 2-4)? If these are from another Table or from a Form you must make it clear.

Concerning ItemNumber, it appears that this is coming from your Form? If it is a numerical value (Item Numbers could be either, depending on how they are formatted), then you would remove the single quotes.

However, you also want to be explicit with your references. If ItemNumber is a Variable that you have declared elsewhere in your procedure, then it is fine as is. But, if it is a control on a form, then you would want to use "Me.ItemNumber":

Expand|Select|Wrap|Line Numbers
  1. WHERE tblQuotation.ItemNumber = '" & ItemNumber & "'"
Hope this helps and gets you moving in the right direction.
Sep 25 '14 #2
zmbd
5,501 Expert Mod 4TB
Just to build on TwinnyFo as he has you in the right direction..

1) Explicitly state in your code either DAO or ADO and set a variable to hold the pointer to your database and remember to release the pointer
Expand|Select|Wrap|Line Numbers
  1. DIM zDB as DAO.Database
  2. ...
  3. Set zDB = CurrentDB
  4. ...
  5. Set zDB = Nothing
2) Build your SQL string as TwinnyFo as suggested, just build it in a string variable first....
Expand|Select|Wrap|Line Numbers
  1. sSQL = "UPDATE tblQuotation " & _
  2.    "SET tblQuotation.ItemCategory = " & ItemCategory & ", " & _
  3.    "tblQuotation.ItemDescription = '" & ItemDescription & "', " & _
  4.       (remaining string) 
You can now use a debug.print to print out your SQL string to see how it is resolving.

Call the string variable in the same place you placed the SQL in the execute statement.

ttfn
Sep 26 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: David | last post by:
Hi, I am trying to a field in a Access database, and I have used the code generated by the Web Matrix UPDATE code wizard. When the update function is called, no errors are generated, but no...
0
by: eyalgr | last post by:
Hello, My Access form updates 2 linked tables in Oracle. How can I update a sequence's next value into a not null field that is not in the form, before inserting the first field in the form, so as...
1
by: gchris53 | last post by:
Hello, Any advice on the attached would be greatly appreciated. I am currently customising someone elses database and have the following problem. A date is updated on a form, in database...
2
by: oli insight | last post by:
Hello there, I have found that i cannot update a record via a form if the form has fields from several different tables .... But it works fine if the a the field in the form come from a single...
2
by: pahuja | last post by:
Please can someone tell me if I can use a single Ms Access form for add/modify/delete as well as QUERY BASED ON A PARTICULAR FIELD? I am able to use the form to query on a particular field which...
16
by: John | last post by:
I am looking for VBA code that will work with Access 2003 to enable dragging and dropping a file/folder name from Windows XP Explorer into an Access form's text box. This is a common functionality...
7
by: kpresidente | last post by:
Hello all, I'm trying to transfer the value of a control on an Access form to an Excel worksheet using VBA. The Access form is a single form with all the controls disabled, so that data is "read...
0
by: jesiecraig | last post by:
Hello, I am new to VBA programming - thank you for your help. I am using a form in Access 2007 to update my database. I use a submit button on the form to send all the values into Access. I...
3
by: Tarneem | last post by:
I have error in update code. It work but i not found data in Microsoft Access. This is the code. <html> <body><br><br><br><br><br><br><br><br> <h1><center>Appointment Update <hr> <% dim...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.