He is developing what he hopes to be a successful commerical application. He isn't going to do this.Quote:
Originally Posted by TheMinime
BrailleSchool: Got that example I asked for?
Printable View
He is developing what he hopes to be a successful commerical application. He isn't going to do this.Quote:
Originally Posted by TheMinime
BrailleSchool: Got that example I asked for?
if you are not logged in, the boolean is False, if you are logged in then its set to true. this is what i have.Quote:
Originally Posted by Hack
frmAccessDenied
VB Code:
Private Sub cmdAccessDeniedOK_Click() With frmLoginForm IsLoggedIn = False .Show .txtUsername.Text = vbNullString .txtPassword.Text = vbNullString .txtUsername.SetFocus End With Unload Me End Sub Private Sub Form_Unload(Cancel As Integer) IsLoggedIn = False With frmLoginForm .Show .txtUsername.Text = vbNullString .txtPassword.Text = vbNullString .txtUsername.SetFocus End With Unload Me End Sub
modPublicVariables
VB Code:
Option Explicit Public IsLoggedIn As Boolean
frmAccountDisabled
VB Code:
Private Sub cmdAccountDisabledOK_Click() With frmLoginForm IsLoggedIn = False .Show .txtUsername.Text = vbNullString .txtPassword.Text = vbNullString .txtUsername.SetFocus End With End Sub Private Sub Form_Unload(Cancel As Integer) With frmLoginForm IsLoggedIn = False .Show .txtUsername.Text = vbNullString .txtPassword.Text = vbNullString .txtUsername.SetFocus IsLoggedIn = False End With End Sub
frmSplash
VB Code:
Private Sub Form_Unload(Cancel As Integer) tmrSplash.Enabled = False IsLoggedIn = False End Sub Private Sub imgSplash_Click() IsLoggedIn = False frmLoginForm.Show tmrSplash.Enabled = False Unload Me End Sub Private Sub tmrSplash_Timer() IsLoggedIn = False frmLoginForm.Show Unload Me End Sub
Sub Main as above
frmMain
VB Code:
Private Sub MDIForm_Unload(Cancel As Integer) If gbSubClassMenu Then '/ prevent error if the menu is not subclassed On Error Resume Next '/ release object Call objMenuEx.Uninstall(Me.hwnd, ImageList, MenuEvents) Set MenuEvents = Nothing Set objMenuEx = Nothing End If With Me If .WindowState <> vbMinimized Then SaveSetting "Operations Manager Pro", "Settings", "MDI.L", .Left SaveSetting "Operations Manager Pro", "Settings", "MDI.T", .Top SaveSetting "Operations Manager Pro", "Settings", "MDI.W", .Width SaveSetting "Operations Manager Pro", "Settings", "MDI.H", .Height End If End With Unload frmMain If IsLoggedIn = True Then IsLoggedIn = False With frmLoginForm .Show .txtUsername.Text = vbNullString .txtPassword.Text = vbNullString .txtUsername.SetFocus End With End If End Sub Private Sub mnuLogout_Click() If IsLoggedIn = True Then IsLoggedIn = False frmLoginForm.Show Unload frmMain End If End Sub
frmLoginForm
VB Code:
Option Explicit Private intLoginAttempts As Long Private Sub cmdClose_Click() Unload Me End End Sub Private Sub cmdLogin_Click() Dim strSQL As String Dim strUName As String Dim strPwd As String Dim strOperatorName As String Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Set conn = New ADODB.Connection Set rs = New ADODB.Recordset conn.CursorLocation = adUseClient conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb;Persist Security Info=false" strSQL = "SELECT * " strSQL = strSQL & "FROM Users " strSQL = strSQL & "WHERE Username = '" & txtUsername.Text & "' " strSQL = strSQL & "AND Password = '" & txtPassword.Text & "' " strSQL = strSQL & "AND Disabled = 'No'" 'UNCOMMENT NEXT LINE TO DEBUG SQL STATEMENT 'Debug.Print strSQL rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic If Not (rs.EOF) Then strUName = rs.Fields("Username").Value strPwd = rs.Fields("Password").Value strOperatorName = rs.Fields("Operator").Value End If intLoginAttempts = intLoginAttempts + 1 If txtUsername.Text = strUName And txtPassword.Text = strPwd Then If IsLoggedIn = False Then IsLoggedIn = True frmMain.Show Unload frmLoginForm End If ElseIf intLoginAttempts = 1 Then IsLoggedIn = False frmAccessDenied.Show frmAccessDenied.lblAccessDeniedCaption.Caption = "Login Credentials Mismatch." & vbNewLine & _ "Access Denied" & vbNewLine & _ "Attempt 1 of 4." Exit Sub ElseIf intLoginAttempts = 2 Then IsLoggedIn = False frmAccessDenied.Show frmAccessDenied.lblAccessDeniedCaption.Caption = "Login Credentials Mismatch." & vbNewLine & _ "Access Denied" & vbNewLine & _ "Attempt 2 of 4." Exit Sub ElseIf intLoginAttempts = 3 Then IsLoggedIn = False frmAccessDenied.Show frmAccessDenied.lblAccessDeniedCaption.Caption = "Login Credentials Mismatch." & vbNewLine & _ "Access Denied" & vbNewLine & _ "Attempt 3 of 4." Exit Sub ElseIf intLoginAttempts = 4 Then With frmAccessDenied IsLoggedIn = False .Show .lblAccessDeniedCaption.Top = 40 .lblAccessDeniedCaption.Caption = "Login Credentials Mismatch." & vbNewLine & _ "Access Denied" & vbNewLine & _ "Attempt 4 of 4." & vbNewLine & _ "Accound Disabled. Contact Support." End With strSQL = "UPDATE Users " strSQL = strSQL & "SET Disabled = 'Yes' " strSQL = strSQL & "WHERE Username = '" & txtUsername.Text & "'" conn.Execute strSQL Exit Sub ElseIf txtUsername.Text = strUName And txtPassword.Text = strPwd And rs.Fields("Disabled").Value = "Yes" Then IsLoggedIn = False frmAccountDisabled.Show Exit Sub ElseIf Not rs.EOF And rs.Fields("FullAccess").Value = "Yes" Then 'do nothing Else With frmInternalSplash 'INVENTORY MANAGER .Frame(0).Height = "1455" .Frame(0).Width = "1695" .Frame(0).Top = "480" .Frame(0).Left = "120" .cmdAddProduct.Visible = False .cmdDeleteProduct.Visible = False .cmdEditProduct.Visible = False .cmdSearchProduct.Top = "240" .cmdSearchProduct.Left = "120" .cmdStockControl.Top = "840" .cmdStockControl.Left = "120" 'CLIENT MANAGER .Frame(1).Height = "2055" .Frame(1).Width = "1695" .Frame(1).Top = "2040" .Frame(1).Left = "120" .cmdDeleteClient.Visible = False .cmdEditClient.Top = "840" .cmdEditClient.Left = "120" .cmdSearchClient.Top = "1440" .cmdSearchClient.Left = "120" 'INVOICE MANAGER .Frame(2).Height = "1455" .Frame(2).Width = "1695" .Frame(2).Top = "4200" .Frame(2).Left = "120" 'LOGOUT .Frame(3).Height = "855" .Frame(3).Width = "1695" .Frame(3).Top = "2160" .Frame(3).Left = "1920" 'NAVIGATION HINT .Frame(4).Height = "975" .Frame(4).Width = "1695" .Frame(4).Top = "3120" .Frame(4).Left = "1920" 'HIDE THE ADD/EDIT/DELETE OPERATOR OPTIONS IF YOU DONT HAVE FULL ACCESS .Frame(5).Visible = False End With With frmMain .mnuAddProduct.Visible = False .mnuAddOperator.Visible = False .mnuEditProduct.Visible = False .mnuEditOperator.Visible = False .mnuDelete.Visible = False .mnuDeleteOperator.Visible = False .mnuSettings.Visible = False End With End If frmMain.sbStatusBar.Panels(7).Text = "Welcome to Operations Manager Pro " & strOperatorName & ", you are logged in as " & strUName & "." rs.Close Set rs = Nothing conn.Close Set conn = Nothing End Sub Private Sub Form_Load() cmdLogin.Enabled = False End Sub Private Sub txtPassword_Change() If LenB(txtPassword.Text) = 0 Or LenB(txtUsername.Text) = 0 Then cmdLogin.Enabled = False End If If LenB(txtPassword.Text) = 0 Then If LenB(txtUsername.Text) = 0 Then cmdLogin.Enabled = False End If End If If LenB(txtPassword.Text) > 0 And LenB(txtUsername.Text) Then cmdLogin.Enabled = True End If End Sub Private Sub txtPassword_GotFocus() SelectWholeTextBox txtPassword End Sub Private Sub txtUsername_Change() If LenB(txtPassword.Text) = 0 Or LenB(txtUsername.Text) = 0 Then cmdLogin.Enabled = False End If If LenB(txtPassword.Text) = 0 Then If LenB(txtUsername.Text) = 0 Then cmdLogin.Enabled = False End If End If If LenB(txtPassword.Text) > 0 And LenB(txtUsername.Text) Then cmdLogin.Enabled = True End If End Sub Private Sub txtUsername_GotFocus() SelectWholeTextBox txtUsername End Sub
frmInternalSplash
VB Code:
Private Sub cmdLogout_Click() If IsLoggedIn = True Then IsLoggedIn = False Unload frmMain With frmLoginForm .Show .txtUsername.Text = vbNullString .txtPassword.Text = vbNullString .txtUsername.SetFocus End With End If End Sub
this post and the above is everwhere frmLoginForm is called from.
First, by default, a boolean is False. You do not need to expressly set it to False unless it has been previously set to True, and you need to reset it.
The first suggestion I have is remove all of those lines of code that set it to False at startup. They are unnecessary and confusing.
The second suggestion is this change: Under this line in cmdLogin_Click()set the boolean to True.Code:frmMain.sbStatusBar.Panels(7).Text blah blah
Also, you do not need to test for the condition of IsLoggedIn. If you set it to False and it is already False, then nothing is going to have. Your If statements on this boolean are unnecessary.
I would encaspulate each With/End With that deals with frmLogin thusly:When you set IsLoggedIn to True in the beginning, these with statements will never execute. In cmdLogout_Click, set it to False.VB Code:
If IsLoggedIn = False Then With frmLoginForm .Show .txtUsername.Text = vbNullString .txtPassword.Text = vbNullString .txtUsername.SetFocus End With
If you encapsulate all of the .Show statements in an If IsLoggedIn = False and set IsLoggedIn equal to True in the correct portion of cmdLogin and never set it to False except in cmdLogout, you shouldn't continue to be haunted by frmLogin.
ok. i have removed it from Sub Main()Quote:
Originally Posted by Hack
Quote:
Originally Posted by Hack
VB Code:
frmMain.sbStatusBar.Panels(7).Text = "Welcome to Operations Manager Pro " & strOperatorName & ", you are logged in as " & strUName & "." If IsLoggedIn = False Then IsLoggedIn = True End If
Does it work?