Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2006
    Posts
    559

    Unanswered: Login screen, query, yes/no, works BUT...

    Ok, the code below is on a command button on my login form. After the user enters their user name and password, they then click "Login". Upon a successful login, a query is ran for 'over-due tasks' by which are tasks that are over 7 days old from the day they were originally started.

    If the user clicks "yes" then the reminder form is displayed with all of the query results. If they click "no" it then takes them to the main menu form.

    THIS ALL WORKS!

    HOWEVER... the problem is that before I put in the code to run the query with the overdue tasks, the security in the db would check the level of security of the user, output to the screen their security level and THEN open the main menu form with their security rights there (ie: viewable admin command button for the admin menu).


    The code does not do this anymore. I am searching to figure out why, but can't seem to find it. Can anyone decipher it and tell me where I went wrong?

    Bryan

  2. #2
    Join Date
    Aug 2006
    Posts
    559
    Code:
    Private Sub cmdOk_Click()
    If isPasswordOK(Me!txtPassword) = True Then
        DoCmd.Close acForm, "frmUserLogon"
        Else
    'Run query to see if there are any overdue tasks using qryReminder
    'Send output of "If tasks are overdue, then ask user if they wish to view
    'User can select Yes/No
    
    Dim lngCount As Long
    
    lngCount = Nz(DCount("DaysSinceOriginated", "qryReminder"), 0)
    
    If lngCount > 0 Then
    
        If MsgBox("There are " & lngCount & " overdue tasks. Would you like to view the overdue tasks?", vbYesNo + vbExclamation) = vbYes Then
            DoCmd.OpenForm "frmReminders"
        Else
            DoCmd.OpenForm "frmMainMenu"
        End If
        
    'Else
    
        'DoCmd.OpenForm "frmMainMenu"
    End If
    
        ' MsgBox "Password incorrect....try again."
        ' Modify this with your code below
    'End If
    'Exit Sub
    
    On Error GoTo Err_cmdOk_Click
    '--------------------------------------------------------------------------
    ' This code is used to validate users found in the tblSecurity table. If the wrong user name or password is
    ' provided access is denied.
    ' Created by: Richard Rensel
    ' Date Created: 18 Feb 2002
    ' Modified by Nick Phillips
    ' MODIFICATIONS: If Wrong Name/password is entered, then the NT login name is grabbed and updated to tblFailedAttempts
    ' Also if the wrong password is entered three times the Login is disabled until it is unlocked by an Admin
    ' This will now check to see if the person is denied access, and if they are the DB is closed, and also if their
    ' password has been reset they are forced to change their password once they enter in the random reset password
    ' Date Modified: 19 feb 2002
    '-----------------------------------------------------------------------------------------------------------------------------
        Dim db As DAO.Database
        Dim rst As DAO.Recordset
        Dim rst1 As DAO.Recordset
        Dim rstV As Recordset
        Dim stDocName As String
        Dim stLinkCriteria As String
        
        Set db = CurrentDb()
        Set rst = db.OpenRecordset("tblSecurity", dbOpenDynaset)
        
        If Not IsNull(Me.txtUser) And Not IsNull(Me.txtPassword) Then
            rst.FindFirst "Password = '" & Me.txtPassword & "'" & " And UserID = '" & Me.txtUser & "'"
        
        '----------------------------------------
        'If their is a problem logging in the NT username is grabbed and appended to tblFailedAttempts. The reason
        'I chose the NT login in name vs. the UserID, is because many times people will browse a network and find
        'A database and start trying to break-in. This way you can get them the first time they enter a wrong name/PW
        'This WILL NOT let you know if a valid user is attempting to log-in while signed onto a computer under another
        'NT log-in name
        
                If rst.NoMatch Then
                Set rst1 = db.OpenRecordset("tblFailedAttempts", dbOpenDynaset)
                With rst1
                    .AddNew
                    ![computer_login] = Me.txtUser_hidden
                    .Update
                End With
                MsgBox "You entered the wrong User Name or Password." & Chr(13) & _
                "Please enter the correct User Name and Password or " & Chr(13) & _
                "contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
        'This counts how many times a user has typed in the wrong UserID/Password combo. After three attempts the user is
        'suspended from the DB, and cannot get access until their account is reset by the Admin
        
                cnt = cnt + 1 'increment counter if wrong password entered
                If cnt = 3 Then  'Set up number of tries
                    'Display Message Box
                    MsgBox "Access Violation Program Will Now Close", , "Violation Detected"
                    DoCmd.OpenForm "frmPWChangeCheck", , , , , acHidden
                    [Forms]![frmPWChangeCheck]![Active] = False
                    DoCmd.Quit 'quit application and close Access
                End If
    
                ElseIf Me.txtPassword = "password" Then
    JumpIn:
    
    
                MsgBox "This is the first time using the database or your password has been reset." & Chr(13) & _
                "You must change your password before you can enter the database.", _
                vbOKOnly + vbExclamation, "Change Password"
                
    JumpIn1:
                stDocName = "frmUserLogonNew"
                stLinkCriteria = "[UserID]=" & "'" & Me![txtUser] & "'"
                DoCmd.OpenForm stDocName, , , stLinkCriteria
            Else
                'This opens another hidden form, that has two values on it... PWChange, and Active. If the active check box
                'is blank, then the user is denied access to the database. This value gets set to "NEW" When a users password
                'is reset from the Admin Users form. This next if/then statement checks to see if the word "NEW" is there
                'and if it is, then it forces the user to change it by going back above with the JumpIn: statement!!
                
                DoCmd.OpenForm "frmPWChangeCheck", , , , , acHidden
                
                    If [Forms]![frmPWChangeCheck]![Active] = False Then
                        MsgBox "Your Database privileges have been revoked" & Chr(13) & _
                        "Please contact the Database Administrator for assistance", vbOKOnly + vbCritical, "Logon Denied"
                        DoCmd.Quit
                    Else
                        If [Forms]![frmPWChangeCheck]![PWChange] = "New" Then
                                GoTo JumpIn:
                        Else
                   
                        
                        
    '############This is the password DATE validation code #############
                        
        DoCmd.OpenForm "frmPasswordHistory", , , , , acHidden
                        
        Select Case Forms!frmPasswordHistory.DaysOld
    
        Case -50
            If vbYes = MsgBox("10 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
            End If
        Case -51
            If vbYes = MsgBox("9 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
            End If
        Case -52
            If vbYes = MsgBox("8 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
            End If
        Case -53
            If vbYes = MsgBox("7 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
            End If
        Case -54
            If vbYes = MsgBox("6 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
            End If
        Case -55
            If vbYes = MsgBox("5 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
            End If
        Case -56
            If vbYes = MsgBox("4 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
            End If
        Case -57
            If vbYes = MsgBox("3 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
            End If
        Case -58
            If vbYes = MsgBox("2 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
            End If
        Case -59
            If vbYes = MsgBox("1 day before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
            End If
        Case -60
                MsgBox "Your password Has expired.You must change it before you can Log In", vbOKOnly + vbCritical, "Invalid Password"
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
        Case Is < -60
                MsgBox "Your password Has expired.You must change it before you can Log In", vbOKOnly + vbCritical, "Invalid Password"
                DoCmd.Close acForm, "frmPasswordHistory"
                GoTo JumpIn1:
        Case Else
            ' user is fine - do nothing
    End Select
                
    '############# END PASSWORD DATE VALIDATION CODE##################
                        
                                DoCmd.Close acForm, "frmUserLogon", acSaveNo 'close the frmUserLogon screen
                                'stDocName = "frmMainMenu" 'open frmMainMenu upon correct login being entered
                                'DoCmd.OpenForm stDocName, , , stLinkCriteria
                        End If
                    End If
            End If
        Else
            MsgBox "You left the User Name and/or Password blank." & Chr(13) & _
            "Please enter the correct User Name and Password or " & Chr(13) & _
            "contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
        End If
        
        With User
            .AccessID = rst.Fields("AccessID")
            .ViewID = rst.Fields("ViewID")
            .Active = rst.Fields("Active")
            .Password = rst.Fields("Password")
            .SecurityID = rst.Fields("SecurityID")
            .UserID = rst.Fields("UserID")
        End With
        
        rst.Close
        
    Exit_cmdOk_Click:
        Exit Sub
    
    
    Err_cmdOk_Click:
        MsgBox Err.Description
        Resume Exit_cmdOk_Click
    End If 'I added
    
    End Sub

  3. #3
    Join Date
    Aug 2006
    Posts
    559
    Ok, I've even tried to take out the query from the top of it and it still doesn't want to go back to the way it was.

    **On a side note, stupid me never backed up the working one PRIOR to putting in the code so I have nothing to fall back on.

    I don't know if it's because I'm not using the same computer and actually typing in my name I use on the other computer / bypassing the original startup with "shift" ?

    You think that can be the cause?

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Bryan,

    Just a note after quickly looking at the code above (I'm not sure if this is related to your problem or not - I'll have to look at it closer)....as a general rule it's always a good idea to close any open recordsets you have on a form before you open any other forms or execute any queries. Not issuing a rst1.close or closing open recordsets and opening other hidden forms or running queries while a recordset is left open can lead to problems.

    With rst1
    .AddNew
    ![computer_login] = Me.txtUser_hidden
    .Update
    End With

    Where do you close rst1? It seems like you're leaving this open (but it's been a while since I've coded in DAO).

    It seems like you're opening one or more hidden forms with both rst and rst1 recordsets still open which I don't think is a good idea. I'm not a fan of opening forms up as hidden (usually you can accomplish the same thing with functions) or writing values to a blank (invisible) text box on the same form.

    I guess my first question would be why do you need to open up forms as hidden? (I haven't seen your other posts where you might have explained this)
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    "HOWEVER... the problem is that before I put in the code to run the query with the overdue tasks, the security in the db would check the level of security of the user, output to the screen their security level and THEN open the main menu form with their security rights there (ie: viewable admin command button for the admin menu)."

    "The code does not do this anymore. I am searching to figure out why, but can't seem to find it. Can anyone decipher it and tell me where I went wrong?"


    After you open the frmMainMenu, I believe you then want to call the function I added (or do whatever code your security level check is):

    docmd.openform "frmMainMenu"
    if isadmin() = true then Forms!frmMainMenu!cmdAdmin.visible = true else Forms!frmMainMenu!cmdAdmin.visible = false

    or I believe you can also do this on the frmMainMenu On Open event (which might be a better option).
    Last edited by pkstormy; 06-02-07 at 18:32.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Here's a Function where you can easily return the security level (i.e. AccessTitle) for the user on the form. Just create an unbound textbox on the frmMainMenu and set the Control Source of the unbound text box = retSecurityLevel() (and of course make the textbox locked and disabled.) You can thus, do this on any form. I encourage you to utilize the power of functions as this will make your life a lot easier. Just modify the strSQL statement below if this sql string doesn't work for you (I like to design a query, then view it as SQL, and then copy and paste the sql statement - strSQL = "<paste>".)


    Just copy and paste this into the Check For Admin module:

    Function retSecurityLevel() As String
    'So retSecurityLevel returns the string value of AccessTitle. Just issue an =retSecurityLevel to call it (i.e. SomeVariable =retSecurityLevel)
    ' or set the Control Source on the textbox =retSecurityLevel.
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Dim strSQL As String
    strSQL = "SELECT tblSecurity.User_Name, tblSecurityAccess.AccessTitle" _
    & " FROM tblSecurityAccess INNER JOIN tblSecurity ON tblSecurityAccess.AccessID = tblSecurity.AccessID" _
    & " WHERE User_Name = '" & fOSUserName() & "'"
    rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
    If rs.EOF And rs.BOF Then
    retSecurityLevel = "User Not Found in tblSecurity!"
    Else
    retSecurityLevel = rs!AccessTitle
    End If
    rs.Close
    Set rs = Nothing
    End Function
    Last edited by pkstormy; 06-02-07 at 19:01.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  7. #7
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Here are the other functions I wrote which where in that module in case you need them again:

    Function isAdmin() As Boolean
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Dim strSQL As String
    strSQL = "Select * from tblSecurity where User_Name = '" & fOSUserName() & "' and AccessID = 1"
    rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
    If rs.EOF And rs.BOF Then
    isAdmin = False
    Else
    isAdmin = True
    End If
    rs.Close
    Set rs = Nothing
    End Function

    Function isNewUser() As Boolean
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Dim strSQL As String
    strSQL = "Select * from tblUsers where User_Name = '" & fOSUserName() & "'"
    rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
    If rs.EOF And rs.BOF Then
    MsgBox "New User detected...Opening New User form."
    isNewUser = True
    Else
    isNewUser = False
    End If
    rs.Close
    Set rs = Nothing
    End Function

    Function isPasswordOK(PWPassed As String) As Boolean
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Dim strSQL As String
    strSQL = "Select * from tblSecurity where User_Name = '" & fOSUserName() & "'"
    rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
    If PWPassed = rs!Password Then
    isPasswordOK = True
    Else
    isPasswordOK = False
    End If
    rs.Close
    Set rs = Nothing
    End Function

    Function NeedToChangePassword() As Boolean
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Dim strSQL As String
    strSQL = "Select * from tblSecurity where User_Name = '" & fOSUserName() & "'"
    rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
    If rs!Password = "Password" Then
    NeedToChangePassword = True
    Else
    NeedToChangePassword = False
    End If
    rs.Close
    Set rs = Nothing
    End Function
    Last edited by pkstormy; 06-02-07 at 19:06.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  8. #8
    Join Date
    Aug 2006
    Posts
    559
    WOW! Paul, ok, thanks for taking the time to look at it.

    I'm going to print this stuff out and read through it. I didn't do the Security of this db, I found a demo of it on the net and used it cause I like it rather than the built-in ULS of Access. I just customized the forms for my organization.

    I'll let you know if there are any further issues with the solutions / suggestions you provided, trust me on that! I'll post it here.

    When this db is actually finalized, I'm thinking about zipping it and putting it in the code-bank incase someone else needs it or some thing like it.

  9. #9
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Bryan,

    I was looking at your code a little more and I had some free time so I thought I'd give you another way to get the date difference in the tblPassword_Old verses having to open up the frmPasswordHistory.

    DoCmd.OpenForm "frmPasswordHistory", , , , , acHidden <==== No need to open a form up in a hidden mode. See the function below which returns the getdatediff

    Select Case Forms!frmPasswordHistory.DaysOld <===== No need to call to that form.

    The above 2 lines can be replaced by the function below:
    You would call the function by simply declaring a variable and setting it to the function:

    Dim DataDif as integer
    DateDif = getdatediff()

    ############This is the password DATE validation code #############
    Select Case DateDif

    Case -50
    If vbYes = MsgBox("10 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    End If
    Case -51
    If vbYes = MsgBox("9 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    End If
    Case -52
    If vbYes = MsgBox("8 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    End If
    Case -53
    If vbYes = MsgBox("7 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    End If
    Case -54
    If vbYes = MsgBox("6 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    End If
    Case -55
    If vbYes = MsgBox("5 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    End If
    Case -56
    If vbYes = MsgBox("4 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    End If
    Case -57
    If vbYes = MsgBox("3 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    End If
    Case -58
    If vbYes = MsgBox("2 days before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    End If
    Case -59
    If vbYes = MsgBox("1 day before your password expires. Want to change it now?", vbYesNo Or vbExclamation, "Password?") Then
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    End If
    Case -60
    MsgBox "Your password Has expired.You must change it before you can Log In", vbOKOnly + vbCritical, "Invalid Password"
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    Case Is < -60
    MsgBox "Your password Has expired.You must change it before you can Log In", vbOKOnly + vbCritical, "Invalid Password"
    DoCmd.Close acForm, "frmPasswordHistory"
    GoTo JumpIn1:
    Case Else
    ' user is fine - do nothing
    End Select

    Function GetDateDiff() As Integer
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Dim strSQL As String
    strSQL = "SELECT tblSecurity.User_Name, tblPasswords_Old.ChangeDate" _
    & " FROM tblPasswords_Old INNER JOIN tblSecurity ON" _
    & " tblPasswords_Old.UserID = tblSecurity.UserID" _
    & " WHERE (((tblSecurity.User_Name) = '" & fOSUserName() & "'))" _
    & " ORDER BY tblPasswords_Old.ChangeDate DESC"
    rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
    If rs.EOF And rs.BOF Then
    GetDateDiff = 0
    Else
    Dim GD As Date 'Format it as a shortdate
    GD = Format(rs!ChangeDate, "mm/dd/yyyy")
    GetDateDiff = DateDiff("d", Date, GD)
    End If
    rs.Close
    Set rs = Nothing
    End Function

    It just makes it so you don't have to open up a form in a hidden view (cleaner) but I'm not sure how that routine was working for you. I'm trying to send you as many examples of functions as I can your way. When you write your first few ones, it's a little scrary (like jumping in the pool for the first time) , but once you've tread water and learned to swim, You'll be glad you did.

    If you decide to try it, let me know how it works out for you.
    Last edited by pkstormy; 06-03-07 at 03:24.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  10. #10
    Join Date
    Aug 2006
    Posts
    559
    Ok, when I got into work, I had the db that I'm working on WITHOUT the messup I did at the house! Yippie Yippie!!!

    So now it works the way it used to, the query and the form is there. I'm wondering however, if I put the "run query / open reminder" on the 'on open' event just after it posts the User's access level?

    Wonder if that'll work?


    ******EDIT******

    Ok, I put the query code to run after it outputs the user level to the screen. It opens the form, frmReminders, but also opens the MainMenu form. Now I have to figure out how to code it so that if the user selects:

    "Yes" to the reminders, then it WON'T open the frmMainMenu
    "No" to the reminders, then it will continue on to the frmMainMenu
    Last edited by Grafixx01; 06-04-07 at 12:09.

  11. #11
    Join Date
    Aug 2006
    Posts
    559
    Ok, done some research, figure a Select Case statement would work.

    gotta figure out now how to write it cause I don't really understand how the coding would go. I understand the concept, just not the coding...

  12. #12
    Join Date
    Aug 2006
    Posts
    559
    Anyone see any issues with this as the code for the "Select Case" statement to stop the 'frmMainMenu' from opening right away:

    Code:
    ------------------------------------ NEW CODE ------------------------
    
    Dim lngCount As long
    
    lngCount = Nz(DCount("DaysSinceOriginated", "qryReminder"), 0)
    
    If lngCount > 0 Then
    
    	MsgBox("There are " & lngCount & " overdue tasks. Would you Would you like to view the overdue tasks?", vbYesNo + vbExclamation
    
    Select Case
    
    	Case 1,  vbYes
    
    		DoCmd.OpenForm "frmReminders"
    
    	Case 2, vbNo
    
    		DoCmd OpenForm "frmMainMenu"
    
    End Select Case
    
    End If

  13. #13
    Join Date
    Aug 2006
    Posts
    559
    Ok, figured out the code to make it work. Just a problem of having it run each time "Main Menu" command buttons are clicked is my MAJOR PROBLEM now.

    I only want it to run the first time the user logs in, kind of like a "run once" statement.

    code for the "on load event" is:

    Code:
    Private Sub Form_Open(Cancel As Integer)
    If isAdmin = True Then
        MsgBox "Recognize AccessID = 1..."
        Me.cmdAdminMenu.Visible = True
    Else
        Me.cmdAdminMenu.Visible = False
    End If
    
    'Run query, qryReminder, to see if there are any overdue tasks within the database that are NOT closed.
    'Send a message box prompting the user if they would like to see the overdue tasks, if any (via Yes / No)
    'Select "Yes", opens frmReminders with query ran for user to select option
    'Select "No", opens frmMainMenu
    
    Dim lngCount As Long
    
    lngCount = Nz(DCount("DaysSinceOriginated", "qryReminder"), 0)
    
    If lngCount > 0 Then
    
      Select Case MsgBox("There are " & lngCount & " overdue tasks. Would you Would you like to view the overdue tasks?", vbYesNo + vbExclamation)
      
      Case vbYes
        
        DoCmd.Close acForm, "frmMainMenu" 'closes frmMainMenu form if the user selects "Yes" to view the reminders
        DoCmd.OpenForm "frmReminders"
            
        Case vbNo
        
        DoCmd.OpenForm "frmMainMenu"
    
    End Select
    
    End If
      
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •