We need to use the recordsetcount attribute to determine whether the data in the database is empty before using movenext and other methods of the recordset object:
CopyCodeThe Code is as follows: dim objrs as new recordset
Dim objcn as new connection
Dim strsql as string
Objcn. connectionstring = "filedsn = student. DSN; user_id = sa; Password = 123"
Objcn. Open
Strsql = "select * From student_info"
Objrs. Open strsql, objcn, adopenkeyset, adlockoptimistic
'In this case, if it is null, the user will be notified and the operation will be performed to exit the module.
If objrs. recordsetcount = 0 then
Msgbox "Student Status information does not exist. Please add the information before proceeding! "
Objrs. Close
Set objrs = nothing
Do not forget to exit sub. Otherwise, an error is reported because the operation is still performed later.
End if (){
}
In this way, we can solve this problem and continue the subsequent operations. If we write a function that links to the database and returns the record to the recordset, we can skip this step!