如何解决对象变量或with块未设置问题?
我用adodc控件连接的数据库,要在数据库的学生表中插入一条记录,我该选什么命令呢?
命令类型:8-adcmdunknown,1-adcmdtext,2-adcmdtable,4-adcmdstroedproc
代码:
Private Sub Form_Load()
'Me.Move Screen.Width - 100, Screen.Height - 50
Adodc1.Recordset.AddNew [color=#FF0000]??执行到这儿就提示:对象变量或with 块变量未设置.[/color]
Private Sub 录入_Click()
On Error GoTo errMsg
If 班级.Text = "" Then
MsgBox "班别不能为空,请核实!", vbOKOnly + vbExclamation, "系统提示"
班级.SetFocus
Exit Sub
End If
'学号
If Text1.Text = "" Then
MsgBox "学号不能为空,请核实!", vbOKOnly + vbExclamation, "系统提示"
Text1.SetFocus
Exit Sub
End If
'Adodc1.RecordSource = "select * from 学生"
'Adodc1.Recordset.MoveFirst
'Do While Not Adodc1.Recordset.EOF
' If Text1.Text = Adodc1.Recordset.Fields("学号") Then
' MsgBox "学号重复,请重新输入!", vbOKOnly + vbExclamation, "退出询问"
' Text1.SetFocus
'Exit Sub
'End If
'Adodc1.Recordset.MoveNext
'Loop
'姓名
If Text2.Text = "" Then
MsgBox "姓名不能为空,请核实!", vbOKOnly + vbExclamation, "系统提示"
Text2.SetFocus
Exit Sub
End If
'电话
If Text3.Text = "" Then
MsgBox "电话不能为空,请核实!", vbOKOnly + vbExclamation, "系统提示"
Text3.SetFocus
Exit Sub
End If
Adodc1.Recordset("学号") = "& Text1.Text &"
Adodc1.Recordset("姓名") = "& Text2.Text &"
Adodc1.Recordset("性别") = "& sex.Text &"
Adodc1.Recordset("系别") = "& 所在系.Text &"
Adodc1.Recordset("专业") = "& 专业.Text &"
Adodc1.Recordset("电话") = "& 电话.Text &"
Adodc1.Recordset("年龄") = "& 年龄.Text &"
Adodc.Recordset.Update
Form_Load
'出错提示
errMsg:
If Err.Number <> 0 Then
MsgBox Err.Number & Err.Description, vbOKOnly + vbCritical, "出错提示"
End If
End Sub
谢谢各位的问答,急!