VB 關聯資料庫的問題 ,救急:
以下是我的程式,datPerson,datScore分別是學生佪人資料和成績資料的
Data Control,這段程式碼是可按toolbar上面的按鈕,分別在表單上顯示
學生全部資料的第一筆,上一筆,下一筆,最後一筆.
datPerson,datScore是以座號關聯.座號在datPerson是p_seatno欄位,
在datScore是s_seatno欄位.
程式執行發生的錯誤是 :
當按下一筆或上一筆,而碰到的資料是某學生只有個人資料,而無成績資料時,
再按下一筆或上一筆,則出現錯誤訊息 :
"This action was cancelled by an associated object"
單步偵錯,發現錯誤發生在^^^^^^^^^^^^^^^^那一行.
我增加已經mark起來的那幾行也沒用!
請問高手,這問題該如何解決 ?
萬分感激!!
chsu@mail.pagic.net
Private Sub tlbTool_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim sSeatNo As String
If datPerson.Recordset.RecordCount = 0 Then
Exit Sub
End If
Select Case Button.Description
Case "first"
datPerson.Recordset.MoveFirst
Case "previous"
datPerson.Recordset.MovePrevious
If datPerson.Recordset.BOF Then
datPerson.Recordset.MoveFirst
End If
Case "next"
datPerson.Recordset.MoveNext
If datPerson.Recordset.EOF Then
datPerson.Recordset.MoveLast
End If
Case "last"
datPerson.Recordset.MoveLast
End Select
txtNo = datPerson.Recordset("p_no")
txtSeatNo = datPerson.Recordset("p_seatno")
txtName = datPerson.Recordset("p_name")
cboSex.Text = datPerson.Recordset("p_sex")
sSeatNo = datPerson.Recordset("p_seatno")
If datScore.Recordset.RecordCount <> 0 Then
datScore.Recordset.FindFirst "s_seatno = '" + sSeatNo + "'"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If Not datScore.Recordset.NoMatch Then
txt_S_SeatNo = datScore.Recordset("s_seatno")
txtChinese = datScore.Recordset("s_chinese")
txtEnglish = datScore.Recordset("s_english")
txtMath = datScore.Recordset("s_math")
txtTotal = datScore.Recordset("s_total")
Else
'datScore.Recordset.MoveFirst
'datScore.Recordset.MoveLast
'datScore.Refresh
txt_S_SeatNo = ""
txtChinese = ""
txtEnglish = ""
txtMath = ""
txtTotal = ""
End If
End If
End Sub