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

Recordset update problem

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 2143
debasisdas
8,127 Expert 4TB
before assigning the value to recordset use rs.edit
Jan 24 '08 #2
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 256MB
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
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
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
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
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...
0
by: belacyrf | last post by:
Here's the code: ------------------------------------------------------------------- accessID = request("accessID") strSQL = "SELECT * From PendingAccRequests Where AccessID = "&accessID ...
22
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...
3
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...
5
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...
2
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...
3
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...
5
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...
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...
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...
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
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...
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
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...

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.