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 = ""
   
    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
    Dim UserName 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 = ""
            End If
        End If
    End If
    
    miCount = miCount + 1
    If miCount = 3 Then
        Me.Hide
    End If
    Exit Sub
End Sub报这个   Dim mrc As ADODB.Recordset    出错,说用户为定义类型是怎么回事啊!
  还有Set mrc = ExecuteSQL(txtSQL, MsgText)  说子程序或函数为定义!我用的是开发实例上的代码,他上面没有定义,我怎么办!!

解决方案 »

  1.   

    Public username As String
    Dim MsgText As String
    Public iAdmin As BooleanPrivate Sub Command2_Click()
    If Text1.Text = "" And Text2.Text = "" Then
        MsgBox "请输入用户名!", , "提示"
    ElseIf Text1.Text = "" Or Text2.Text = "" Then
        MsgBox "用户名或密码未输入完全!", , "提示"
        Text1.Text = ""
            Text2.Text = ""
    Else
    Dim strpwd As String
    Dim iAdmin As Boolean
    username = Text1.Text
    strpwd = Text2.Text txtSQL = "select * from user "
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        If mrc.EOF = False Then
            With mrc
                Do While Not .EOF
                   If username = mrc!user And strpwd = mrc!pwd Then
                   
                        iAdmin = mrc!admin
                        Unload Me
                        index.Show
                        If iAdmin <> True Then
                            index.light.Enabled = False
                            index.findkq.Enabled = False
                            index.un.Panels(4).Text = "欢迎 " & username & " 登入!"
                        Else
                            index.light.Enabled = True
                            index.findkq.Enabled = True
                            index.un.Panels(4).Text = "欢迎 " & username & " 登入!"
                        End If
        
                        
                                            
                        Exit Sub                End If                .MoveNext
                Loop
            End With
            MsgBox "用户名或密码错误!", vbQuestion, "错误!"
            Text1.Text = ""
            Text2.Text = ""
        Else
            MsgBox "数据库连接错误!清检查系统DSN连接;单击确定退出!", , "错误!"
        End If
    End If
    End Sub
    这个是我做的登入窗口,但是要先连接odbc中的dsn~!ado我没事过,但是语句你可以试下~!