473,779 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recordset update problem

30 New Member
I've written the following code to update a recordset but when I run it I get a Run-time error 3020: Update or CancelUpdate without AddNew or Edit. When I debug it highlights the rs.update line. I've serached this forum and others for an answer but no luck. Anyone got any ideas? Thanks

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Public Function fImportdata()
  4. Dim db As DAO.Database
  5. Dim rs As DAO.Recordset
  6. Set db = CurrentDb()
  7. Set rs = db.OpenRecordset("Import Query", dbOpenDynaset)
  8. With rs
  9. .MoveFirst
  10. .Edit
  11. While .EOF = False
  12.      If rs![M1] = "Y" And rs![M2] <> "Y" Then
  13.         rs![M2] = "Y" ' Will update M2 with a Y if M1=Y and M2 is null.
  14.         GoTo MyLabel
  15.     Else
  16.     End If
  17.     If rs![M2] = "Y" And rs![M3] <> "Y" Then
  18.         rs![M3] = "Y" 'Will update M3 with a Y if M1=Y and M2 is null.
  19.         GoTo MyLabel
  20.     Else
  21.     End If
  22.     If rs![M3] = "Y" And rs![M4] <> "Y" Then
  23.         rs![M4] = "Y"
  24.         GoTo MyLabel
  25.     Else
  26.     End If
  27.     If rs![M4] = "Y" And rs![M5] <> "Y" Then
  28.         rs![M5] = "Y"
  29.         GoTo MyLabel
  30.  
  31.     End If
  32. MyLabel:
  33.     rs.Update
  34.     rs.MoveNext
  35. Wend
  36. End With
  37. rs.Close
  38. End Function
Jan 24 '08 #1
5 2160
debasisdas
8,127 Recognized Expert Expert
before assigning the value to recordset use rs.edit
Jan 24 '08 #2
fieldling
30 New Member
before assigning the value to recordset use rs.edit
I have put .edit in line 10. Is this incorrect?
Jan 24 '08 #3
daniel aristidou
491 Contributor
Im noy sure which version vb ure usin form the code
But try adding an end edit command just before update..
Jan 24 '08 #4
fieldling
30 New Member
Im noy sure which version vb ure usin form the code
But try adding an end edit command just before update..
Thanks for your help.
It's version 6.3
It doesn't recognise the EndEdit command although I may not have done it correctly. How would you put that command in?
Jan 24 '08 #5
fieldling
30 New Member
Im noy sure which version vb ure usin form the code
But try adding an end edit command just before update..
Hi I've managed to fix it and all running smoothly. Thanks for your help.
Jan 24 '08 #6

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

Similar topics

7
2162
by: ANC | last post by:
hi, i would like to ask how can i set a field of recordset to be editable? thanks in advance. ANC
7
5053
by: Rob Meade | last post by:
Lo all, I'm having a little bit of trouble (betty...). I have removed some of the obvious stuff from this example (like connections being opened/closed etc) I create a recordset in ASP (not linked to a database) Set testRS = Server.CreateObject("ADODB.RecordSet")
0
1532
by: belacyrf | last post by:
Here's the code: ------------------------------------------------------------------- accessID = request("accessID") strSQL = "SELECT * From PendingAccRequests Where AccessID = "&accessID 'Create the Recordset object and run SQL statement Set accRS = Server.CreateObject ("ADODB.Recordset") accRS.Open strSQL, objConn
22
2896
by: Gerry Abbott | last post by:
Hi all, I having some confusing effects with recordsets in a recent project. I created several recordsets, each set with the same number of records, and related with an index value. I create a table and add the index value and a value/s from each recordset in turn, into a temporary table, which I used to create a report. I created this with DAO objects, and it worked fine. I use iteration, and the ..movenext command to get the next...
3
35468
by: alex_peri | last post by:
Hello All, I am having problems with sorting a recordset by fields in Access. I have a table with three columns called ID, SNo and Time and would like to sort the records by Time. I would like to sort them in the actual database and not just Order them with SQL. I have included the code I wrote below. Please bear in mind that I am very new to Access and SQL. I used the Helpfile of Access for this code but i can't make it work for me....
5
3637
by: msprygada | last post by:
I am having a problem with getting a recordset to fill with data in an Access Data Project from a SQL Server database. Here is the code example that is in the Access help files that I can get to work just fine: Dim Cnxn As ADODB.Connection Dim rstEmployees As ADODB.Recordset Dim strCnxn As String Dim strSQLEmployees As String
2
2068
by: Corey | last post by:
I am missing something here. I have a pop up form (loads from the "main form")that displays multiple command buttons. When a user selects a particular button, the recordset from the main form should be updated. Here is the code that I have written but it doesnt work. I get too few parameters on rs1. Can anyone shed some light on what I am missing? I appreciate help in advance-Corey Private Sub APPRVD_Click()
3
6901
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records from rsSource into rsDest - if it finds a key violation then it deletes the current record from rsDest and adds the new record from rsSource. This works perfectly - but only for the first found duplicate record, it brings up the error
5
2514
by: zMisc | last post by:
Are there any tricks in updaitng a JOINed recordset? I joned to tables and when I try to change a field on the recordset and update it, I get this error: "Unknown column 'CCDE' in 'where clause'. CCDE is a field from one of the table and is not a field I am updating. I uses MyODBC with VB6 and MySQL 5.
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...
0
9636
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
10306
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
10139
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...
1
10075
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
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...
1
7485
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
5373
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...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.