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 txtSQL As String Dim mrc As ADODB.Recordset Dim MsgText As String Dim miCount As Integer
Private Sub Form_Load() Dim i As Integer i = 0 txtSQL = "select * from user_Form" Set mrc = ExecuteSQL(txtSQL, MsgText) With txtUserName Do While Not mrc.EOF i = i + 1 .AddItem Trim(mrc!user_ID) mrc.MoveNext Loop .ListIndex = i - 1 End With mrc.Close OK = False miCount = 0 End Sub
Private Sub cmdCancel_Click() OK = False Me.Hide End Sub
Private Sub cmdOK_Click() txtSQL = "select * from user_Form 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 miCount = miCount + 1 If miCount = 3 Then Me.Hide End If Exit Sub End Sub
Private Sub txtPassword_KeyDown(KeyCode As Integer, Shift As Integer) EnterToTab KeyCode End Sub
Private Sub txtPassword_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Call cmdOK_Click End If End Sub
Private Sub txtUserName_Click() txtPassword.Text = "" End Sub
Private Sub txtUserName_KeyDown(KeyCode As Integer, Shift As Integer) EnterToTab KeyCode End Sub 再以上这段代码中,老有未设置变量的错误,请高手指教,具体该怎么改啊