Option Explicit
Dim rs As ADODB.Recordset
Dim SD As Boolean
Private function checkclass() As Boolean '检测添加的课程是否重复
On Error GoTo errh
' Adodc2.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=db5.MDB;" & _
"DefaultDir=" & CheckPath(App.path) & ";" & _
"UID=;PWD=;"
Set rs = cn.Execute("SELECT 课程号 FROM 课程 WHERE 课程号='" & Trim(Text1.Text) & "'")
' Adodc2.RecordSource = "select * from 课程 where 课程号='" & Trim(Text1.Text) & "' and 课程名称='" & Trim(Text2.Text) & "' "
If rs.EOF Then
rs.Close
checkclass = True
Exit function
End If
checkclass = False
rs.Close
Exit function
errh:
rs.Close
MsgBox Err.Description
End functionPrivate Sub Command1_Click()
On Error GoTo errh
If Text1.Text <> "" Then
If Text2.Text <> "" Then
If Text3.Text <> "" Then
If checkclass Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("课程号").Value = Text1.Text
Adodc1.Recordset.Fields("课程名称").Value = Text2.Text
Adodc1.Recordset.Fields("授课老师").Value = Text3.Text
Adodc1.Recordset.Update
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
MsgBox "添加成功!"
'Adodc1.Refresh
Else
MsgBox "课程重复,请另外输入一门课程!"
Text1.SetFocus
End If
Else
MsgBox "该项不能为空,请输入授课老师姓名!"
End If
Else
MsgBox "该项不能为空,请输入课程名称!"
End If
Else
MsgBox "该项不能为空,请输入课程号!"
End If
'MsgBox("你的操作将关系到所有选这门课的学生,所有这门课的纪录将被删除,你确信吗?", vbOKCancel, "警告") = vbOK Then
'Adodc1.Recordset.Delete adAffectAllChapters
'
'Adodc1.Recordset.UpdateBatch adAffectAllChapters
'DataGrid1.ReBind
Exit Sub
errh:
MsgBox Err.Description
End SubPrivate Sub Command15_Click()
Unload Me
End SubPrivate Sub Command2_Click()
On Error GoTo errh
If MsgBox("你的操作将会删除当前的纪录,你确信吗?", vbOKCancel, "警告") = vbOK Then
If Text1.Text <> "" Then
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM 课程 WHERE 课程号='" & Trim(Text1.Text) & "' ", cn, adOpenDynamic, adLockOptimistic, adCmdText
If rs.EOF Then
rs.Close
MsgBox "没有该课程,无法删除!", vbOKOnly + vbExclamation, "警告"
Text1.Text = ""
Exit Sub
End If
rs.Delete
rs.Update
rs.Close
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
MsgBox "删除成功!"
Else
MsgBox "该项不能为空,请输入课程号!"
End If
End If
Exit Sub
errh:
rs.Close
MsgBox Err.Description
End SubPrivate Sub Form_Load()
On Error GoTo errhMakeCenter DlgCourse
'Text1.SetFocus
' Adodc1.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=学籍.MDB;" & _
"DefaultDir=" & CheckPath(App.path) & ";" & _
"UID=;PWD=;" & _
"PASSWORD=197967yh"
' Adodc1.RecordSource = "SELECT * FROM 课程"
' Adodc1.Refresh
' DataGrid1.ReBind
Exit Sub
errh:
MsgBox Err.Description
End Sub'Private Sub Form_Unload(Cancel As Integer)
'On Error Resume Next
' Adodc1.Recordset.Close
'End Sub
错误提示:对象变量或With块变量未设置
大家能不能帮帮我~!看看什么地方错了~!