473,787 Members | 2,928 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update Query in VBA updates field to -1!?

34 New Member
Hi,

I'm trying to run an update query in vba and i'ts not working. It does the update but the [Limit Level 2] field is updated to "-1".

here's the query:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim stDocName As String
  3. Set rst = New ADODB.Recordset
  4.         stDocName = "SELECT * FROM [Limit Table] WHERE [ID]=" & txtID.Value & ""
  5.         rst.Open stDocName, CurrentProject.Connection
  6.  
  7.         If txtID = "" Or IsNull(txtID) Then
  8.         stDocName = MsgBox("Click on the Row that you want to Update")
  9.     Else
  10.         stDocName = "UPDATE [Limit Table] SET [Limit Level 1]='" & ComboLevel1.Value & "',[Limit Level 2]='" & ComboLevel2.Value & "' AND [Primary/Secondary]='" & ComboPS.Value & "',[Limit Type]='" & ComboType.Value & "',[Limit Amount]='" & txtAmount.Value & "',[Limit Currency]='" & ComboCurrency.Value & "',[Limit Approval Date]='" & txtDate.Value & "' WHERE [ID]=" & txtID
  11.         DoCmd.RunSQL stDocName
  12.         lstTEST.Requery
  13.  
  14.     End If 
[Limit Level 2] is a combobox with a dropdown that depends on what has been chosen in [Limit Level 1]. I have put the code for this in the 'gotfocus' property of ComboLevel2. I think this might have something to do with the problem, although the dropdown works perfectly.

any ideas?

regards,
Riun
Jul 10 '07 #1
1 1711
MMcCarthy
14,534 Recognized Expert Moderator MVP
Is txtID a text or a number field?

You haven't declared rst as a variable (i.e.)

Dim rst As ADODB.Recordset

In your update statement the syntax is wrong

"UPDATE [Limit Table] SET [Limit Level 1]='" & ComboLevel1.Val ue & "', [Limit Level 2]='" & ...."

it should be

"UPDATE [Limit Table] SET [Limit Level 1]='" & ComboLevel1.Val ue & "' AND [Limit Level 2]='" & ...."
Jul 17 '07 #2

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

Similar topics

3
1680
by: Epetruk | last post by:
Hi, I have a mySql question here on updates to multiple tables. Here's a simple schema to clarify things: Structure Table A
1
5186
by: Kunal | last post by:
Hi, I need some help on writing an update query to update "UnitsSold" field in Products Table whenever I save a transaction. The transaction may contain several "Subtransactions", one for each product sold in that transaction. I have a subtransaction table that maintains record of each subtransaction, with data such as: ProductID, Quantity, TransactionID etc. The Products table has fields: ProductID, UnitsSold, UnitsOrdered,...
9
2140
by: James Butler | last post by:
Our setup: Online db: MySQL Inhouse db: MS Access 97 with MySQL tables linked via ODBC Our issue: Almost every field updates successfully, except one. A scenario: Information is written to online db. We run an inhouse query to collect info from online db and update
7
2431
by: PC Datasheet | last post by:
Looking for suggestions ---- A database was designed for a national automobile inspection program. In it's simplest form, the database has two tables: TblOwner OwnerID <Year/Make/Model owned by owner, Owner name/address, etc) TblInspection InspectionID
11
2252
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to reflect that the 3 items have been deleted only to discover that the 3 items appear, however when I click on them to display their information which runs a datareader over the same database it appears that the data has now gone. I wondered whether...
4
3014
by: Ian Davies | last post by:
Hello I have seen some tutorials to put a update a counter field in a record. I have the counter field in a table that also has a field for a path to file. I display the records in a table on a web page e.g. IndexNo ............Title................................ Link .................................... Count ......1.............MyFileName........www.mysite/files/MyFileName.doc........
13
2460
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever works best) to display a dropdown menu of fields populated from table tblInvoiceData. This control also includes a textbox which the user can input a value. These two columns are side by side and not in a vertical layout. The user then clicks on...
4
8798
by: mmanojkumar | last post by:
Sir, I have a recordset "ADODC_path.recordset" which takes input from two tables When the field values are put into the textboxes and then edited and updated back into the tables, using the following codes, everything works fine. "select * from path,Station where path.StationCode=Station.StationCode and path.traincode=" & Text2.Text Two tables Station(fields: StationCode and StationName) and Path(fields: StationCode ,TrainCode...
2
1093
by: uksigma | last post by:
Hi again, I’ve hit another problem, I hope someone can help. I have a table that contains numerous records for the same single record in the other table . The table is therefore related to the in a one-to-many relationship. I have created an update query that I want to update a field in the main table with the sum of all the Unit Costs from the related table. At the moment, it's only updating it with one of them. E.g. there are three...
13
4177
by: Neil | last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been running for 20 minutes so far! The query is quite simple: update a single field in a table, based on a join with another table. There are a total of 1200 rows that are affected (out of a total of 60,000 in the table). Should not take 20 minutes! Also, retrieving the 1200 rows using the same criteria is instantaneous. Anyone have any idea what's going on? Here's...
0
9655
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10169
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.