Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2007
    Posts
    4

    Sending users to a default form based on login

    Good Day!

    I currently have an application that I've created for a work unit. Users must log in using a username and password that has been setup as part of the application.



    What I would like to do (if possible) is send each different user to a default form based on their specific job function. Below is the logon script currently in place within this app:

    Private Sub cmdLogOn_Click()
    On Error GoTo Err_cmdLogOn_Click

    Dim db As DAO.Database
    Dim rst As DAO.Recordset

    Set db = CurrentDb()
    Set rst = db.OpenRecordset("tblUserDetails", dbOpenDynaset)

    If IsNull(Me.txtUserName) Then

    PopUpMsgBox Message1, 2, Title1, vbCritical
    Me.txtUserName.SetFocus
    Call CheckLogAttempts

    ElseIf IsNull(Me.txtPassword) Then

    PopUpMsgBox Message1, 2, Title1, vbCritical
    Me.txtPassword.SetFocus
    Call CheckLogAttempts

    ElseIf Me.txtPassword = "XXXXXXXX" Then 'Admin Password
    DoCmd.OpenForm "frmMain"
    User.UserLevel = 1

    ElseIf Me.txtPassword = "YYYYYYYY" Then 'Emergency Password
    DoCmd.OpenForm "frmUserDetails"

    Else
    User.Password = PerformEncryption(Me.txtPassword, True)
    rst.FindFirst "Password = '" & User.Password & "'" & " And UserName = '" & Me.txtUserName & "'"

    If rst.NoMatch Then
    Call ErrorMessage
    Else
    If PerformEncryption(Me.txtPassword, True) = User.Password Then
    With User
    .UserName = Me.txtUserName
    .UserLevel = rst.Fields("UserLevelID")
    .UserID = rst.Fields("UserID")
    .Active = rst.Fields("Active")
    End With

    rst.Close
    If User.Active = False Then
    MsgBox " Your User account has been suspended. " & Chr(13) & "Please contact your System Administrator " & Chr(13) & " to have your account reset.", vbExclamation, " Log On Error"
    Me.txtPassword = ""
    Me.txtUserName = ""
    Me.txtUserName.SetFocus
    User.Password = ""
    Else
    DoCmd.OpenForm "frmMain"
    Call fLogUser(1)
    DoCmd.Close acForm, Me.Name
    End If

    Else

    Call ErrorMessage

    End If
    End If
    End If

    Exit_cmdLogOn_Click:
    Exit Sub

    Err_cmdLogOn_Click:
    Select Case Err.Number
    Case 94
    Call ErrorMessage
    Resume Exit_cmdLogOn_Click
    Case Else
    MsgBox Err.Description, vbCritical, " Log On Error"
    Resume Exit_cmdLogOn_Click
    End Select

    End Sub

    What I would like to do now is send the user (on successful login) to the default form that is stipulated within the DefaultForm field of the tblUserDetails table. If no default form is stipulated in the DefaultForm field, they get sent to the frmMain Form.

    Any ideas??

  2. #2
    jya is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2007
    Location
    Chicagoland
    Posts
    109
    Don't know if this would work, but have you tried moving the rst.close to the end of the subroutine and putting in an IF statement to check for the Default form?


    If IsNull(rst.Fields("DefaultForm")) then
    Docmd.open "frmMain"
    Else
    Docmd.open rst.Fields("DefaultForm") 'I'm assuming it will be a valid form
    End If

    rst.close

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Login Screen in Access
    By Di7bash in forum Access
    Replies: 3
    Last Post: 03-18-2014, 11:57 PM
  2. Form Based Query/Filter
    By Micon in forum Access
    Replies: 0
    Last Post: 11-07-2008, 09:25 AM
  3. Database Login Error
    By narasareddy in forum Access
    Replies: 0
    Last Post: 08-30-2008, 12:00 AM
  4. Run a PivotChart form based on query
    By Suzan in forum Queries
    Replies: 0
    Last Post: 06-11-2006, 03:48 AM
  5. Open form based on Subform criteria
    By Suzan in forum Programming
    Replies: 0
    Last Post: 04-25-2006, 02:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums