live error 3021

VB Example: Student System Summary (3)

——Classic error 2: Real-time error 3021

"Real-time error 3021 Either BOF or EOF is true, or the current record is deleted, the desired operation requires a current record." error in the student system is second only to the error mentioned in the previous blog post "Realtime error ' 91 '"

This error generally occurs in window code such as modification, query, etc.!

Let's briefly talk about the difference between BOF and EOF.

BOF, EOF attributes:

BOF indicates that the current record position is before the first record of the Recordset object.

EOF indicates that the current record position is after the last record of the Recordset object.

return value:

The BOF and EOF properties return Boolean values.

To learn more about the meaning and usage of BOF and EOF, please refer to the following links:

http://blog.csdn.net/mrbaymax/article/details/77415669

The problems I encountered during the debugging process, the specific locations are shown in the figure:

This problem occurs because there is no record in the database. The program segment added to this problem is shown in the following figure:

Let's briefly analyze this simple code

 If mrc.RecordCount = 0 Then 'Query the number of data records in the database

        MsgBox "There is no record, please close the modification window!", vbOKOnly + vbExclamation, "Warning" 'If there is no relevant data in the database, a warning window will pop up

       'Invalidate the button control in the query window when there is no relevant data in the database

 cmdFirst.Enabled = False

        cmdPrevious.Enabled = False

        cmdNext.Enabled = False

        cmdLast.Enabled = False

         cmdcancel.Enabled = False

        cmdDelete.Enabled = False

        cmdEdit.Enabled = False

        cmdUpdate.Enabled = False

      Else

      mrc.MoveFirst

      

      Call viewdata

      myBookmark = mrc.Bookmark

      mcclean = True

      End If

This program can be adapted to most of the "real-time error 3021" in the student system

The specific modification should be modified and used according to your own situation.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325991332&siteId=291194637