Results 1 to 6 of 6
  1. #1
    IAFerrari is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    15

    After Login I want to open a Forum with the worker details but only show by worker ID

    I created a database with worker information. I created a login that a worker can log in to the database and go to worker details. Issue I want to do is I want only the person that log in to see his or her information and cannot look at other records. So when worker goes to the login page he or she will login in with their first name then the password is the worker ID number. After login with go to the forum worker details with the person that login in information with the correct worker ID that is the same as password. Right know I can get the worker details forum to open but cannot get it to go directly to the person name that is logging in , Here is my code. Thanks for your Help
    John

    Private Sub Command1_Click()
    Dim User As String
    Dim UserLevel As Integer
    Dim TempPass As String
    Dim ID As Integer
    Dim workerName As String
    Dim TempLoginID As String


    If IsNull(Me.txtUserName) Then
    MsgBox "Please enter UserName", vbInformation, "Username requeired"
    Me.txtUserName.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please enter Password", vbInformation, "Password requeired"
    Me.txtPassword.SetFocus
    Else
    If (IsNull(DLookup("LoginID", "tblworker", "LoginID = '" & Me.txtUserName.Value & "' And password = '" & Me.txtPassword.Value & "'"))) Then
    MsgBox "Invalid UserName or Password!"
    Else
    TempLoginID = Me.txtUserName.Value
    workerName = DLookup("[workername]", "tblworker", "[LoginID] = '" & Me.txtUserName.Value & "'")
    UserLevel = DLookup("[UserType]", "tblworker", "[LoginID] = '" & Me.txtUserName.Value & "'")
    TempPass = DLookup("[password]", "tblworker", "[LoginID] = '" & Me.txtUserName.Value & "'")
    ID = DLookup("[workerid]", "tblworker", "[LoginID] = '" & Me.txtUserName.Value & "'")
    DoCmd.Close


    If (TempPass = "password") Then
    MsgBox "Please change Password", vbInformation, "New password requeired"
    DoCmd.OpenForm "frmUserinfo", , , "[workerid] = " & ID
    Else

    DoCmd.OpenForm "Worker Details"
    End If

    End If
    End If
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Have you stepped through the code and made sure that ID contains the appropriate value? Your OpenForm should work, presuming it has the correct value and the workerid field is numeric.

    Edit: I should clarify that the first OpenForm, with the wherecondition should work. The second is unfiltered.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    IAFerrari is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    15
    Where would I the where Claus at?
    Thanks
    Jkhn

  4. #4
    Pommetje77 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Location
    the Netherlands
    Posts
    37
    Why not using tempVar?
    There is a very good example at the Northwind database.
    So login using tempVar, store tempVar somewhere in your Homescreen (visible or non-visible textbox/combobox) and open all screens in reference to this textbox/combobox.
    Ruud

  5. #5
    IAFerrari is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    15
    I not the best at coding can you give me a example
    Thanks
    John

  6. #6
    Pommetje77 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Location
    the Netherlands
    Posts
    37
    I personally would add a combobox with your workers names, so the employee is always using the correct names.


    Private Sub cmdLogin_Click()
    Dim TempLoginID as TempVars
    Static intLogonAttempts As Integer
    intLogonAttempts = intLogonAttempts + 1

    TempVars!TempLoginID = me.[YourComboboxName].value

    'Check to see if data is entered into the UserName combo box
    If IsNull(Me.[YourComboboxName]) Or Me.[YourComboboxName] = "" Then
    MsgBox "You must select an Employee Name.", vbOKOnly, "Required Data"
    Me.[YourComboboxName].SetFocus
    Exit Sub
    End If


    'Check to see if data is entered into the password box
    If IsNull(Me.txtpassword) Or Me.txtpassword = "" Then
    MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
    Me.txtpassword.SetFocus
    Exit Sub
    End If

    'Check value of password in tblEmployees to see if this matches the criteria
    'Check if checkbox "Change Password" is checked and open employee form to change password

    If Me.txtpassword.Value = DLookup("strEmpPassword", "tblEmployees", _
    "[ID]=" & Me.cboEmployee.Value) Then
    If Me.cmdChangePassword = True Then
    DoCmd.OpenForm "frmPasswordChange", , , "[ID] = " & Me.cboEmployee
    Me.cmdChangePassword = False
    Exit Sub
    End If
    End If

    'Check value of password in tblEmployees to see if this
    'matches value chosen in combo box

    If Me.txtpassword.Value = DLookup("strEmpPassword", "tblEmployees", _
    "[ID]=" & Me.cboEmployee.Value) Then
    lngMyEmpID = Me.cboEmployee.Value
    DoCmd.Close acForm, "frmLogon", acSaveNo
    DoCmd.OpenForm "frmSplash"
    intLogonAttempts = 0
    Exit Sub
    'If User Enters incorrect password 3 times database will shutdown
    ElseIf intLogonAttempts > 2 Then
    MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
    TempVars.RemoveAll
    Application.Quit
    Else
    MsgBox ("Incorrect password, Please try again!"), vbOKOnly, "Error!", 0, 0
    Me.txtpassword.Value = ""
    Me.txtpassword.SetFocus
    End If
    'intLogonAttempts = 0
    End Sub

    So you set the TempVar username with the TempVars!TempLogin. Once you are logged in, you can call the tempVar (username)
    by calling =[TempVars]!TempLoginID. So if you would like to open the workers properties screen, you can open it something like:

    DoCmd.OpenForm "YourFormName", acNormal, "", "[ID] =" & [TempVars]!TempLoginID, , acNormal

    Be informed that a combobox is providing you a number value, this number value is the employee- or workers ID.
    In the open form action, you should then providing the numbervalue (which is stored as TempVar) of the employee to be openend!

    There are lots of examples on google when searching on Login and TempVars.
    Hope this helps
    Ruud

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

Similar Threads

  1. Add worker working time
    By Japi67 in forum Forms
    Replies: 6
    Last Post: 11-07-2015, 02:07 PM
  2. Co-worker can't link to dbase file, but I can
    By rando1000 in forum Import/Export Data
    Replies: 10
    Last Post: 08-05-2014, 05:59 PM
  3. Outstanding Worker
    By Micky in forum Queries
    Replies: 11
    Last Post: 04-09-2012, 02:14 PM
  4. Design table - keeping worker status
    By snoopy2003 in forum Database Design
    Replies: 8
    Last Post: 02-23-2011, 12:48 PM
  5. Asynchronous programming or background worker
    By troubleduser in forum Programming
    Replies: 0
    Last Post: 12-03-2010, 01:46 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