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

Run time error '3021' message

2
Am currently working with VB 6.0 and Win7 OS. My application is linked with Microsoft Access 2007 (2002-2003 file format) database and whenever I want to update a record in a table from the Access database the project will display a message "Run-time error '3021' Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record."
The challenge I have is on line 10 that's where my project halts. Would there be any approach I can use to continue with my project. Below is the code for update procedure.

Expand|Select|Wrap|Line Numbers
  1. Private Sub updateButton_Click()
  2.    If rs.State = adStateOpen Then rs.Close
  3.    Con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\NDASS.mdb"
  4.    rs.Open "SELECT*FROM Details where RegNumber='" & txtSearch.Text & "'", _
  5.                 Con, adOpenKeyset, adLockPessimistic
  6.    If rs.BOF Or rs.EOF = True Then
  7.       rs.update
  8.       txtRegNo.Text = rs![RegNumber]
  9.       txtSurname.Text = rs!Surname
  10.       txtMiddleName.Text = rs!MiddleName
  11.       txtOtherName.Text = rs!Othernames
  12.       cboDOB1.Text = rs!DOB1
  13.       cboDOB2.Text = rs!DOB2
  14.       cboDOB3.Text = rs!DOB3
  15.       imgPassport.Picture = LoadPicture(rs!Passport)
  16.       '
  17.       txtCivilianPersonnelName.Text = rs!CivilianPersonnelName
  18.       txtOffBusAddress.Text = rs!civilianOfficeBusinessAddress
  19.       txtEmailNDACivilian.Text = rs!CivilianEmail
  20.       txtPhoneNDACivilian.Text = rs!CivilianPhoneNumber
  21.       cboClassApplied.Text = rs!ClassApplied
  22.       cboSpecialDisability.Text = rs!SpecialDisability
  23.       '
  24.       rs.Update
  25.       MsgBox "Record updated!", vbOKOnly + vbInformation, "Modify"
  26.    End If
  27.    rs.Close
  28.    Set rs = Nothing
  29.    '
  30.    Con.Close
  31.    Set Con = Nothing
  32. End Sub
Jan 23 '13 #1
3 5340
zmbd
5,501 Expert Mod 4TB
line 8 in code block should be rs.edit
This will still error if the connection is bad or there isn't a currently selected record.

Line 7 doesn't make sense... you're editing the BOF (first record) or the EOF (last record)?

The remaining code makes no sense in that it appears that you are changing the values of controls on the form, not copying values from the controls to the records.
Jan 23 '13 #2
Ovees
2
Thanks for your response. I still don't get it clear how can I modify the values in a control and then update it to a database please
Jan 24 '13 #3
zmbd
5,501 Expert Mod 4TB
Let's just look at line 8 in the OP code block:
txtRegNo.Text = rs![RegNumber]

In "english" what you are saying by this code is (in simple terms):
With the control named "txtRegNo" let the property of that control named "Text" have the value of the field [RegNumber] in the recordset assigned to "rs"

where what you need is:
rs![RegNumber] = txtRegNo.Text
let the field [RegNumber] in the recordset assigned to "RS" have the value taken from the property named "Text" from the control named "txtRegNo".
Jan 24 '13 #4

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

Similar topics

1
by: Colin Graham | last post by:
I am writing this piece of code to show the previous record on a control on the form but i keep getting the error message "Error 3021 no current record " and the line marked *** gets highlighted. I...
9
by: Robert Wing | last post by:
I support an MS Access application in which errors are trapped using the On Error statement. Just recently, the users of this system have experienced run-time error number 3021 on a random basis. ...
3
by: Richard Hollenbeck | last post by:
I've marked the line in this subroutine where I've been getting this error. It may be something stupid but I've been staring at this error trying to fix it for over an hour. I'm pretty sure the...
0
by: Newcomer | last post by:
Hi everybody, For sure an easy thing for you to solve. But for me as non expert I cannot find the mistake. I wrote an easy find command as shown here Range("A:A").Select
1
by: darrel | last post by:
Hi there, can someone tell me what is wrong with my code am getting a run time error 3021: Here my code: If rs.State = adStateOpen Then rs.Close rs.Open "Select * from where ID like...
2
by: littleclayjar | last post by:
On a filter form, I have three search criteria. When i click the button to "Clear Selection", I get a 'Run-time error '3021 - No current record' if any one of the criteria has not been selected. So...
0
by: bssandeshbs | last post by:
I am developing a Address Book Database Project using Visual Basic 6... When i click the delete button the data does'nt get deleted in the FrontEnd ..But it gets deleted in Database when we see in...
1
by: ekawj | last post by:
Dear Teacher, I wrote program like below, Sub getdts() Dim ix, iy As Integer Dim tz, dz As String Dim V1A, V2A
7
by: hpesoj | last post by:
When i copy data form to multiple form i get a "Run-time error 3021. No current record " in the line "rst2.MoveLast"...Can you help me out... Private Sub Process_AfterUpdate() Dim db As...
2
by: Laneyshia | last post by:
Hello Again. I have been proceeding through my code, thanks to you guys, and although this particular line may not be needed it is giving me this error that does not make sense. When asked to...
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:
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
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
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.