求教一个登陆窗口按回车会再次加载窗体
为什么我按回车登陆成功后,再次按回车会再次打开这个登陆窗口?就是show出窗口form7或form3后点击form7或form3中任何一个按钮都会再次打开登录窗口,是不是标准模块变量出问题了?
标准模块就只有这一句:Public cksl As Long
form3或form7窗口中就这么一句:
Private Sub Command1_Click()
cksl = cksl - 2
Form2.Show
Unload Me
End Sub
登录窗口
代码如下:
'cksl是一个模块公共变量,其他窗口也有用到
Option Explicit
Dim dlcs As Integer '尝试登陆次数
Private Sub Command2_Click() '退出
cksl = cksl - 2 '窗口数量-2
Unload Me
End Sub
-----------------------------------------------------------
Private Sub Command1_Click() '登陆
If Me.Text1 = "" Then
MsgBox "用户名不能为空!", vbCritical, Me.Caption
Me.Text1.SetFocus
Exit Sub
ElseIf Me.Text2 = "" Then
MsgBox "请填写密码!", vbCritical, Me.Caption
Me.Text2.SetFocus
Exit Sub
End If
= adCmdText
Adodc1.RecordSource = "select * from [user] where 用户名 = '" & Trim(Text1.Text) & "' "
Adodc1.Refresh
If Adodc1.Recordset.RecordCount = 0 Then
MsgBox "用户名或密码错误!", vbInformation, Me.Caption
GoTo ExitSub
End If
If Adodc1.Recordset.Fields("密码") <> Text2.Text Then
MsgBox "用户名或密码错误!", vbInformation, Me.Caption
GoTo ExitSub
End If
If Adodc1.Recordset.Fields("权限") = "业务员" Then
Unload Me
Form7.Show
ElseIf Adodc1.Recordset.Fields("权限") = "管理员" Then
Unload Me
Form3.Show
End If
ExitSub:
dlcs = dlcs + 1 '登陆次数+1
If dlcs = 4 Then
MsgBox "请与管理员联系!", vbInformation, Me.Caption
Unload Me
End If
End Sub
------------------------------------------------------
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
cksl = 2
dlcs = 0
Show
Me.Text1.SetFocus
End Sub
---------------------------------------------
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) '按回车
If KeyCode = 13 Then
Text2.SetFocus
End If
End Sub
--------------------------------------------------------
Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer) '按回车
If KeyCode = 13 Then
Call Command1_Click
End If
End Sub
---------------------------------------------------------
Private Sub Text1_KeyPress(KeyAscii As Integer) '消除按回车的声音
If KeyAscii = 13 Then
KeyAscii = 0
End If
End Sub
---------------------------------------------------------
Private Sub Text2_KeyPress(KeyAscii As Integer) '消除按回车的声音
If KeyAscii = 13 Then
KeyAscii = 0
End If
End Sub
[ 本帖最后由 wxflw 于 2012-4-17 20:44 编辑 ]