Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
Public OK As Boolean
'记录确定次数
Dim miCount As Integer
Private Sub Form_Load()
    Dim sBuffer As String
    Dim lSize As Long
    sBuffer = Space$(255)
    lSize = Len(sBuffer)
    Call GetUserName(sBuffer, lSize)
    If lSize > 0 Then
        txtUserName.Text = "1234"
   
    Else
        txtUserName.Text = vbNullString
    End If
        OK = False
    miCount = 0
End SubPrivate Sub cmdCancel_Click()
    OK = False
    Me.Hide
End Sub
Private Sub cmdOK_Click()
    Dim txtSQL As String
    Dim mrc As ADODB.Recordset
    Dim MsgText As String
    'ToDo: create test for correct password
    'check for correct password
    
    UserName = ""
    If Trim(txtUserName.Text = "") Then
        MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
        txtUserName.SetFocus
    Else
        txtSQL = "select * from user_Info where user_ID = '" & txtUserName.Text & "'"
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        If mrc.EOF = True Then
            MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
            txtUserName.SetFocus
        Else
            If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
                OK = True
                mrc.Close
                Me.Hide
                UserName = Trim(txtUserName.Text)
            Else
                MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
                txtPassword.SetFocus
                txtPassword.Text = "1234"
            End If
        End If
    End If
    
    miCount = miCount + 1
    If miCount = 3 Then
        Me.Hide
    End If
    Exit Sub
End Sub
Private Sub Label2_Click()End SubPrivate Sub lblLabels_Click(Index As Integer)End SubPrivate Sub txtPassword_Change()End SubPrivate Sub txtUserName_Change()End Sub

解决方案 »

  1.   

    我看了看,好像密码是写在数据库的
    If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then 
                    OK = True 
                    mrc.Close 
                    Me.Hide 
                    UserName = Trim(txtUserName.Text) 
                Else 
                    MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告" 
                    txtPassword.SetFocus 
                    txtPassword.Text = "1234" 
                End If 密码在user_Info 表中的第二个字段
      

  2.   

    那是不是的安装SQL数据库?这是一个学生管理系统,不知道用户名和密码?
      

  3.   

    如何把frmMain.frm把它设置成启动窗体进去再加个用户?添加用户?
      

  4.   

    打开你的user_Info 表就可以看到用户名列表和密码了。
    当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html