就是这个!
不管打开还是关闭,都不对!
Private Sub cmdReg_Click()
    'Dim cmd As Command
    
    Usertype = General
    State = 1
 
    Set cmd = New Command
    DataE.Connections("conLibrary").Open
    cmd.ActiveConnection = DataE.Connections("conLibrary")
    cmd.CommandText = "insert into UserTable(UserName,RealName,pwd,RegisterTime,age,state,usertype) values('" & txtUserName.Text & "','" & txtRealName.Text & "','" & txtPassword.Text & "','" & Now & "','" & udAge.Value & "','" & State & "','" & Usertype & "')"
    cmd.CommandText = "select * from usertable where username='" & txtUserName & "'"
    '子段不要使用关键字“PassWord”
    '验证重要信息已经填写
    If txtUserName.Text = "" Then
        MsgBox "请填写用户名!", vbOKOnly + vbInformation, "注意"
        txtUserName.SetFocus
        Exit Sub
    ElseIf txtPassword.Text = "" Then
        MsgBox "请填写密码!", vbOKOnly + vbInformation, "注意"
        txtPassword.SetFocus
        Exit Sub
    ElseIf txtPwAgain.Text = "" Then
        MsgBox "请填写确认密码!", vbOKOnly + vbInformation, "注意"
        txtPwAgain.SetFocus
        Exit Sub
    
    End If
    
    If txtPassword.Text <> txtPwAgain.Text Then
        MsgBox "两次密码不相同,请重新填写!", vbOKOnly + vbInformation, "注意"
        txtPassword.Text = ""
        txtPwAgain.Text = ""
        txtPassword.SetFocus
        Exit Sub
    End If
    
    On Error GoTo exit1
    If Not IsExistUser(txtUserName, "") Then
    '添加用户
        DataE.cmdAdd txtUserName, txtPassword, txtRealName, txtUnit, Now, udAge, Usertype, State
        
        MsgBox "注册成功!", vbOKOnly + vbInformation, "注意"
        Unload Me
        frmSearch.Show
    Else
        MsgBox "用户已经存在!请重新注册一个新的用户名", vbOKOnly + vbInformation, "注意"
        txtUserName.Text = ""
        txtPassword.Text = ""
        txtPwAgain.Text = ""
        txtUserName.SetFocus
    End If
    Exit Sub
   
    
exit1:
    MsgBox "数据未成功写入数据库!", vbOKOnly + vbInformation, "错误"
    Exit Sub
End Sub
