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

Update Query in VBA updates field to -1!?

34
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 1694
MMcCarthy
14,534 Expert Mod 8TB
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.Value & "', [Limit Level 2]='" & ...."

it should be

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

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

Similar topics

3
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
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...
9
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...
7
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...
11
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...
4
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...
13
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...
4
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...
2
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 ...
13
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.