VB连接数据库添加信息时出错
在录入数据时出现“ 实时错误91,对象变量或WITH块变量未设置”我的按钮代码是Private Sub CmdPresentation_Click()
Dim mrc As ADODB.Recordset
Set mrc = New ADODB.Recordset
Dim txtSQL As String
Dim MsgText As String
If Not Testtxt(TxtName.Text) Then
MsgBox "请输入姓名!", vbOKOnly + vbExclamation, "警告"
TxtName.SetFocus
Exit Sub
End If
If Not Testtxt(CboGender.Text) Then
MsgBox "请选择性别!", vbOKOnly + vbExclamation, "警告"
CboGender.SetFocus
Exit Sub
End If
If Not Testtxt(TxtAge.Text) Then
MsgBox "请输入年龄!", vbOKOnly + vbExclamation, "警告"
TxtAge.SetFocus
Exit Sub
End If
If Not Testtxt(TxtJiGuan.Text) Then
MsgBox "请输入籍贯!", vbOKOnly + vbExclamation, "警告"
TxtJiGuan.SetFocus
Exit Sub
End If
If Not Testtxt(TxtNation.Text) Then
MsgBox "请输入民族!", vbOKOnly + vbExclamation, "警告"
TxtNation.SetFocus
Exit Sub
End If
If Not Testtxt(TxtProfession.Text) Then
MsgBox "请输入职业!", vbOKOnly + vbExclamation, "警告"
TxtProfession.SetFocus
Exit Sub
End If
If Not Testtxt(TxtXueLi.Text) Then
MsgBox "请输入学历!", vbOKOnly + vbExclamation, "警告"
TxtXueLi.SetFocus
Exit Sub
End If
If Not Testtxt(TxtChangZhuDiZhi.Text) Then
MsgBox "请输入常住地址!", vbOKOnly + vbExclamation, "警告"
TxtChangZhuDiZhi.SetFocus
Exit Sub
End If
If Not Testtxt(TxtTeleNum.Text) Then
MsgBox "请输入电话!", vbOKOnly + vbExclamation, "警告"
TxtTeleNum.SetFocus
Exit Sub
End If
If Not Testtxt(TxtGuiDangNum.Text) Then
MsgBox "请输入归档号!", vbOKOnly + vbExclamation, "警告"
TxtGuiDangNum.SetFocus
Exit Sub
End If
If Not Testtxt(TxtGuiDangTime.Text) Then
MsgBox "请输入归档年度!", vbOKOnly + vbExclamation, "警告"
TxtGuiDangTime.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(TxtAge.Text)) Then
MsgBox "年龄请输入数字!", vbOKOnly + vbExclamation, "警告"
TxtAge.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(TxtTeleNum.Text)) Then
MsgBox "电话请输入数字!", vbOKOnly + vbExclamation, "警告"
TxtTeleNum.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(TxtQQ.Text)) Then
MsgBox "QQ请输入数字!", vbOKOnly + vbExclamation, "警告"
TxtQQ.SetFocus
Exit Sub
End If
If Not IsDate(TxtGuiDangNum.Text) Then
MsgBox "归档号应输入日期格式(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
TxtGuiDangNum.SetFocus
Else
TxtGuiDangNum = Format(TxtGuiDangNum, "yyyy-mm-dd")
txtSQL = "select * from TiZhi_Infomation"
Set mrc = ExecuteSQL(txtSQL, MsgText)
mrc.AddNew
mrc.Fields(0) = Trim(TxtName.Text)
mrc.Fields(1) = Trim(CboGender.Text)
mrc.Fields(2) = Trim(TxtAge.Text)
mrc.Fields(3) = Trim(TxtJiGuan.Text)
mrc.Fields(4) = Trim(TxtNation.Text)
mrc.Fields(5) = Trim(TxtProfession.Text)
mrc.Fields(6) = Trim(TxtXueLi.Text)
mrc.Fields(7) = Trim(TxtChangZhuDiZhi.Text)
mrc.Fields(8) = Trim(TxtQQ.Text)
mrc.Fields(9) = Trim(TxtEmail.Text)
mrc.Fields(10) = Trim(TxtTeleNum.Text)
mrc.Fields(11) = Trim(TxtGuiDangNum.Text)
mrc.Fields(12) = Trim(TxtGuiDangTime.Text)
mrc.Fields(13) = Trim(TxtLikeGanTian.Text)
mrc.Update
MsgBox "添加信息成功!", vbOKOnly + vbExclamation, "警告"
mrc.Close
Me.Hide
End If
For Each textobj In Controls
If TypeOf textobj Is TextBox Then
textobj.Text = ""
End If
Next
TxtName.SetFocus
End Sub