主要代码如下:
Option ExplicitPrivate Sub cmdCancel_Click()
Unload Me
End SubPrivate Sub cmdOK_Click()
Dim rstLogin As New adodb.Recordset
Dim strPwd As String
Static intTimes As Integer On Error Resume Next With rstLogin
If .State = adStateOpen Then .Close
.ActiveConnection = gcnnReport
.CursorLocation = adUseClient
.Source = "SELECT user_id,user_name, password " & _
"from [gsgl_sggl].[dbo].[yhdl_user] " & _
"WHERE user_id = " & Val(txtUserName)
.Open
End With
Static ntrycount As Integer If rstLogin.EOF Then
MsgBox "对不起你的密码不正确,请重新输入!", vbCritical, "错误"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName)
ntrycount = ntrycount + 1
If ntrycount > 3 Then
MsgBox "你已经没有机会了!!", vbCritical + vbOKOnly, "登录失败"
Unload Me End If
Else
Load fMain
Unload Me
End If
End Sub
Private Sub Form_Load()End SubPrivate Sub lblLabels_Click(Index As Integer)End Sub
错误在于,用户错误有3次或cancel后却自动进入主界面?
Option ExplicitPrivate Sub cmdCancel_Click()
Unload Me
End SubPrivate Sub cmdOK_Click()
Dim rstLogin As New adodb.Recordset
Dim strPwd As String
Static intTimes As Integer On Error Resume Next With rstLogin
If .State = adStateOpen Then .Close
.ActiveConnection = gcnnReport
.CursorLocation = adUseClient
.Source = "SELECT user_id,user_name, password " & _
"from [gsgl_sggl].[dbo].[yhdl_user] " & _
"WHERE user_id = " & Val(txtUserName)
.Open
End With
Static ntrycount As Integer If rstLogin.EOF Then
MsgBox "对不起你的密码不正确,请重新输入!", vbCritical, "错误"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName)
ntrycount = ntrycount + 1
If ntrycount > 3 Then
MsgBox "你已经没有机会了!!", vbCritical + vbOKOnly, "登录失败"
Unload Me End If
Else
Load fMain
Unload Me
End If
End Sub
Private Sub Form_Load()End SubPrivate Sub lblLabels_Click(Index As Integer)End Sub
错误在于,用户错误有3次或cancel后却自动进入主界面?
Unload Me该为
end
是退出当前所有程序
你是不是已经载入了主窗体后,然后将登录窗体作为模式窗体显示,要求输入密码?
那么你在三次错误时,应该end,而不是unload me。但我看密码正确时你又load frmmain,
所以,如果没有载入其他的窗体,这些语句并无错误。
不管怎样,将unload me改成end先试一下,应该行的,还是怀疑你已经载入了主窗体。
unload me之后并没有Load fMain
为什么会进入主界面呢
期待...
If ntrycount > 3 Then
MsgBox "你已经没有机会了!!", vbCritical + vbOKOnly, "登录失败"
Unload Me
Exit Sub '*****不要再执行后面的代码
End If
你的工程是否将启动窗口设置为fMain,然后在fMain的初始化事件中启动登录窗口的show方法?1 将登录窗口设置为启动窗口
2 或:
Private Sub cmdCancel_Click()
End
End Sub......
If ntrycount > 3 Then
MsgBox "你已经没有机会了!!", vbCritical + vbOKOnly, "登录失败"
End
End If