Students basically almost the same tune, I found I had a lot of mistakes, here to do some summary.
1.3021
I encountered this error is almost the most mistakes, as long as there is no data, it will pop out this error. Ah, see? I point out this sentence crux of this error is that there is no data, the database can not find data, the so-called "original aim," Just know this, we can quickly resolve this error.
Where students, often where this error happen?
- When ordered to modify student information form, but there is also no student information database, the error appeared, or you will delete all the records,
- Well, how do we deal with it?
Dim mrc As ADODB.Recordset
Dim txtsql As String
Dim msgtext As String
txtsql = "select * from class_Info "
Set mrc = ExecuteSQL(txtsql, msgtext)
If mrc.EOF And mrc.BOF Then
MsgBox "没有数据,请添加!", 0 + 48, 提示
frmaddclassinfo.Show
Exit Sub
Else
frmmodifyclassinfo.Show
End If
I almost eat around the world use this code, as long as I appeared 3021, my first thought would be solved with this code.
Second: When data is deleted, delete records more than two error does not appear, but the error will occur when deleting the last record.
Act 1, the use of error-handling statement (premise: While click the Delete button after an error, but re-open the record has been deleted)
On Error GoTo 1
1:
the If Err = 3021 the Then
MsgBox "has no data, add data", vbOKOnly + vbExclamation, "prompt"
Unload Me
frmaddclassinfo.Show
End the If
Else
mrc.Bookmark = MyBookmark
Call ViewData
End the If
Act 2, written judgment statement to determine whether the last record
Private Sub deleteCommand_Click()
= mrc.Bookmark MyBookmark
str2 $ = MsgBox ( "Delete this record?", vbOKCancel, "delete the current record.")VbOK the Then str2 = $ IF mrc.MoveNext
'determines whether the last recordIf mrc.EOF Then
mrc.MovePrevious
If mrc.BOF Then 'If so, then deleted, to avoid the implementation of the statement call viewdata
mrc.MoveNext
mrc.Delete
Msgbox "record is already empty," vbokonly + vbexclamation, "Warning"
unload me
else
mrc.movefirst
mybookmark=mrc.bookmark
mrc.movelast
mrc.delete
mrc.bookmark=mybookmark
mrc.close
2.91
I already heard this mistake, and sure enough, I met this error and whether they most careful about, such as the SQL statement quotes are not complete, the SQL statement is wrong, more space, less space, will appear this error.
I'm wrong here, because I write the SQL statement is incomplete, the right should be
txtSQL = "select * from student_Info where student_ID = '" & comboSID.Text & "'"
3.3265
This error is not common,
But, here I am wrong, careful not entirely their own, how can the information appears in the Add-grade grade grade information in the form of it. Deleted it.
4. cross-border issues
When you enter data exceeds the range or greater than the desired database, for example, string is limited to 11 digits into the case 10, the error occurs.