Private Sub cmdSave_Click()
        Dim objCopy As New Recordset
        If Len(Trim(txtUser)) <> 5 Then
        MsgBox "用户编号必须为5位字符串!", vbCritical, "系统用户管理"
        txtUser.SetFocus
        txtUser.SelStart = 0
        txtUser.SelLength = Len(txtUser)
        ElseIf Len(Trim(txtPWD)) <> 6 Then
        MsgBox "用户口令必须为6位字符串!", vbCritical, "系统用户管理"
        txtPWD.SetFocus
        txtPWD.SelStart = 0
        txtPWD.SelLength = Len(txtPWD)
        ElseIf Not cmbStatus Like "[0,1,2,3,4]" Then
        MsgBox "用户权限代码必须为0、1、2、3或4!", vbCritical, "系统用户管理"
        cmbStatus = "": cmbStatus.SetFocus
    Else
        Set objCopy = Drug_Store.rsSysUsers.Clone
        With objCopy
           If .RecordCount > 0 Then
           .MoveFirst
           .Find "编号=""&Trim(txtUser)&"""
           If Not .EOF And .AbsolutePosition <> _
                       Drug_Store.rsSysUsers.AbsolutePosition Then
                MsgBox "编号:" & Trim(txtUser) & _
                       "已被使用,请使用其他用户名!", _
                        vbCritical, "系统用户管理"
                txtUser.SetFocus
                txtUser.SelStart = 0
                txtUser.SelLength = Len(txtUser)
                Exit Sub
            End If
        End If
    End With
    Drug_Store.rsSysUsers.Update
    MsgBox "数据保存成功!", vbInformation, "系统用户管理"
    cmdAdd.Enabled = True
    cmdDelete.Enabled = True
    isAding = False
    picNavigation.Enabled = True
    
    End If
    
End Sub要求对象 实时错误‘424’
是什么错误?请各位大侠帮帮忙!

解决方案 »

  1.   

     txtPWD.SetFocus  问题出现在这句
      

  2.   

    那是因为你的窗体上没有名称叫:
    txtPWD
    的 TextBox 控件!
      

  3.   

    如果有,那就不应该出现“要求对象”的错误提示(除非它在别的窗口中!)!按你的代码写法,你的 txtPWD 要与 cmdSave 处于同一个窗口中才行。
      

  4.   

    cmbStatus 这个是什么
    我测试的txtPWD.SetFocus没问题
    倒是cmbStatus.SetFocus这个有问题
      

  5.   

    cmbStatus肯定是个下拉列表框。登录时选择登录状态,类似于‘在线、隐身’等。
      

  6.   

    控件的 .Enabled 属性,是等于 True,还是 False。
    如果等于 False,则会出现错误。
      

  7.   

    楼主既然强调有这文本框 那就有可能它的 Index 有东东 变成数组了...
      

  8.   

    如果想用控件数组 txtPWD(0).text  括号里用什么看index值如果不想用控件数组,删除index值
      

  9.   


    txtPWD控件中没有index值,只是用pictureBox模拟的Data中有index值
      

  10.   

    你的保存按钮和txtPWD在同一个窗体上吗?
      

  11.   

    是的!原来没有加这句: 
    Dim txtPWD As New Recordset
    的时候是要求对象的错误!加了之后就是:未找到方法或数据成员。 
    错误!
      

  12.   

    txtPWD.SetFocus .Recordset 没有SetFocus 的方法啊。你定义名称小心点,怎么能和控件同名了?
      

  13.   


    晕了,加这个干什么?txtPWD 应该是一个控件,应该是textbox控件,到窗体上找
      

  14.   

    问题是窗体上已经有这个控件了!不加Dim txtPWD As New Recordset
    这段代码就是:要求对象 实时错误‘424’ ---
      

  15.   

    txtPWD所在窗体名.txtPWD.SetFocus 试试。
    Dim txtPWD As New Recordset 这句话不要,或者换个名称。
      

  16.   

            txtPWD.SetFocus 
            txtPWD.SelStart = 0 
            txtPWD.SelLength = Len(txtPWD)
    这几个前面都加上所在的窗体名试试