467,075 Members | 1,025 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,075 developers. It's quick & easy.

Run Time Error-3021..Please help

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 Access...
When i try to delete again in VB front End it gives a Error message and it gets

RUN time Error 3021
Either BOF or EOF is true,or current record has been deleted..Requested operation requires a current Record...

I am POSting the Entire Program below..Please Solve my Error





Expand|Select|Wrap|Line Numbers
  1. Dim intCurrAddress As Integer
  2. Dim intSaveupdate As Integer
  3.  
  4.  
  5. Private Sub LoadAddresses()
  6. Dim dbAddress As New ADODB.Connection
  7. Dim rsAddress As New ADODB.Recordset
  8. dbAddress.Open "dsn=Address"
  9. cboAddresses.Clear
  10.  
  11. Set rsAddress = dbAddress.Execute("select * from" & _
  12. " address order by txtLastName")
  13. intCurrAddress = rsAddress("idAddress")
  14. Do Until rsAddress.EOF
  15. cboAddresses.AddItem rsAddress("txtFirstName") & " " & rsAddress("txtLastName")
  16. cboAddresses.ItemData(cboAddresses.NewIndex) = rsAddress("idAddress")
  17. rsAddress.MoveNext
  18. Loop
  19. dbAddress.Close
  20. intSaveupdate = 0
  21. cboAddresses.ListIndex = 0
  22.  
  23. End Sub
  24.  
  25. Private Sub cboAddresses_click()
  26. Dim dbAddress As New ADODB.Connection
  27. Dim rsAddress As New ADODB.Recordset
  28. dbAddress.Open "dsn=Address"
  29.  
  30. If intSaveupdate = 1 Then
  31. SQL = "update address set " & _
  32. "txtFirstName ='" & TxtFirstName.Text & "'," & _
  33. "txtLastName ='" & TxtLastName.Text & "'," & _
  34. "txtAddress ='" & TxtAddress.Text & "'," & _
  35. "txtCity ='" & TxtCity.Text & "'," & _
  36. "txtState ='" & TxtState.Text & "'," & _
  37. "txtZipCode ='" & TxtZipCode.Text & "'," & _
  38. "txtPhone ='" & TxtPhone.Text & "'," & _
  39. "txtFax ='" & TxtFax.Text & "' where idaddress= " & intCurrAddress
  40. dbAddress.Execute SQL
  41. End If
  42. intCurrAddress = cboAddresses.ItemData(cboAddresses.ListIndex)
  43. Set rsAddress = dbAddress.Execute("select * " & "from address where idAddress= " & intCurrAddress)
  44.  
  45. LblIdAddress.Caption = rsAddress("idAddress")
  46. TxtFirstName.Text = rsAddress("txtFirstName")
  47. TxtLastName.Text = rsAddress("txtLastName")
  48. TxtAddress.Text = rsAddress("txtCity")
  49. TxtCity.Text = rsAddress("txtCity")
  50. TxtState.Text = rsAddress("txtState")
  51. TxtZipCode.Text = rsAddress("txtZipCode")
  52. TxtPhone.Text = rsAddress("txtPhone")
  53. TxtFax.Text = rsAddress("txtFax")
  54. dbAddress.Close
  55. End Sub
  56.  
  57. Private Sub CmdAdd_Click()
  58. CmdCancel.Enabled = True
  59. Cmdupdate.Enabled = True
  60. CmdAdd.Enabled = False
  61. cboAddresses.Enabled = False
  62. CmdAddress.Enabled = False
  63.  
  64. LblIdAddress.Caption = " "
  65. TxtFirstName.Text = " "
  66. TxtLastName.Text = " "
  67. TxtAddress.Text = " "
  68. TxtCity.Text = " "
  69. TxtState.Text = " "
  70. TxtZipCode.Text = " "
  71. TxtPhone.Text = " "
  72. TxtFax.Text = " "
  73. intSaveupdate = 0
  74. End Sub
  75. Private Sub CmdAddress_Click()
  76. rptAddress.Show
  77. End Sub
  78. Private Sub cmdupdate_click()
  79. Dim dbAddress As New ADODB.Connection
  80. Dim rsAddress As New ADODB.Recordset
  81. Cmdupdate.Enabled = False
  82. CmdAdd.Enabled = True
  83. cboAddresses.Enabled = True
  84. CmdAddress.Enabled = False
  85. dbAddress.Open "dsn=address"
  86. SQL = " insert into address(txtFirstName,txtLastName," & _
  87. "txtAddress," & _
  88. "txtCity,txtState,txtZipCode,txtPhone,txtFax)" & _
  89. " Values(' " & _
  90. TxtFirstName.Text & " ', ' " & _
  91. TxtLastName.Text & " ', ' " & _
  92. TxtAddress.Text & " ', ' " & _
  93. TxtCity.Text & " ', ' " & _
  94. TxtState.Text & " ', ' " & _
  95. TxtZipCode.Text & " ', ' " & _
  96. TxtPhone.Text & " ', ' " & _
  97. TxtFax.Text & " ')"
  98. dbAddress.Execute SQL
  99. dbAddress.Close
  100. LoadAddresses
  101. End Sub
  102. Private Sub cmddelete_click()
  103. Dim dbAddress As New ADODB.Connection
  104. Dim intResponse As Integer
  105. strResponse = MsgBox("Are You Sure?", vbYesNo, "Delete Query")
  106. If strResponse = 6 Then
  107. dbAddress.Open "dsn=address"
  108. SQL = "delete from address where idaddress= " & intCurrAddress
  109. dbAddress.Execute SQL
  110. LoadAddresses
  111.  
  112. dbAddress.Close
  113. End If
  114.  
  115. End Sub
  116.  
  117.  
  118. Private Sub cmdcancel_click()
  119. LoadAddresses
  120. cboAddresses.Enabled = True
  121. CmdAdd.Enabled = True
  122. Cmdupdate.Enabled = False
  123. CmdCancel.Enabled = False
  124. End Sub
  125.  
  126.  
  127. Private Sub Form_load()
  128. LoadAddresses
  129. End Sub
  130.  
Feb 28 '09 #1
  • viewed: 1643
Share:

Post your reply

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

Similar topics

5 posts views Thread by Carmine Cairo | last post: by
21 posts views Thread by rdemyan via AccessMonster.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.