主题:[讨论]紧急求助对象变量或with块变量未设置
搞了半天怎么都看不出哪里错了,帮忙下
Private 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
Exit Sub
errh:
MsgBox Err.Description
End Sub
运行后出现错误“对象变量或with块变量未设置”
错误定位在adodc1.recordset.addnew
adodc1的控件已经添加,也已经和数据库连接,测试成功的,但就是不知道为什么还是有错误,其他模块也是这样写的都没出错。
高手帮忙啊,这个搞不出,下面的就不好做了,先谢了
Private 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
Exit Sub
errh:
MsgBox Err.Description
End Sub
运行后出现错误“对象变量或with块变量未设置”
错误定位在adodc1.recordset.addnew
adodc1的控件已经添加,也已经和数据库连接,测试成功的,但就是不知道为什么还是有错误,其他模块也是这样写的都没出错。
高手帮忙啊,这个搞不出,下面的就不好做了,先谢了