| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 421 人关注过本帖
标题:VB连接数据库添加信息时出错
只看楼主 加入收藏
日月成星
Rank: 1
等 级:新手上路
帖 子:2
专家分:2
注 册:2009-8-28
收藏
 问题点数:0 回复次数:0 
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
搜索更多相关主题的帖子: 数据库 
2009-08-28 15:07
快速回复:VB连接数据库添加信息时出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028272 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved