top of page

'Remember Me' checkbox of user login system


(Make Your Access Database Look Like a Professional Program. )

Remember Me function simply stores the logged-in computer name and username at the table and finds the user at the start of the database. So you can fill in the username and password automatically.

You can apply this method to your database easily. You may find the codes here. Also, find the previous video of the login system

the first is to to create two fields do use your table 1 Port computer name the

second for username

Put those two fields into the form

put a checkbox onto the form. caption is ‘remember. change the name of the check box as ‘chkremember’ and set the default value as false.

the next step is 2 write some code to on click event of the login button.

Private Sub Command24_Click()
'Entry controls.
If Nz(Me.Combo20) = "" Then MsgBox ("please select username"): Exit Sub
If Nz(Me.txtpassword) = "" Then MsgBox ("please enter your password"): Exit Sub
If Nz(Me.txtpassword) <> Me.password Then MsgBox ("wrong password"): Me.txtpassword.SetFocus: Exit Sub
'if the password is ok

If Me.chkremember Then
    Me.USERcompname = Environ$("computername")
    Me.USERusername = Environ$("username")
    DoCmd.Save acForm, "frmlogin"
    Me.USERcompname = ""
    Me.USERusername = ""
    DoCmd.Save acForm, "frmlogin"
End If

'hide the login form
Me.Visible = False
.cmdtoday.Visible = True
.cmdtomorrow.Visible = True
.cmdweek.Visible = True
.lstmyteam.Visible = True
.List10.Visible = True
.lstmyteam = Me.ID
'Form_FRMMAIN.shapecover.Visible = False
End With
End Sub

code, when the Login is successful I mean after the password check, If

the check box checked active user’s computer and login name will be stored in

the table fields if not those fields will be cleared.

add a little bit of code in to the form load event.

Private Sub Form_Load()

Me.Image115.Top = 0
Me.Image115.Height = Me.InsideHeight

'get the computer and windows username of the current session
    txtcomp = Environ$("computername")
    txtuser = Environ$("username")

    'go to the useer record by using txtuserIDno
    Dim rs As Recordset
    Set rs = Me.Recordset
    rs.FindFirst "[usercompname]='" + txtcomp + "' AND [userusername]='" + txtuser + "'"
    If rs.NoMatch Then
        'if no match nothing happens
      Exit Sub
    End If
    'if mathed, form went to othe user record. code will fill the form automatically
    Me.Combo20 = Me.ID
    Me.txtpassword = Me.password
    Me.chkremember = True
    Me.imguser.Visible = True

End Sub

this code runs at the beginning reads the system information, and compares

it with the user’s table. if both parameters are matched, goes to

the user record and fills in the user information automatically.

Thats it.

351 görüntüleme0 yorum

Son Yazılar

Hepsini Gör


bottom of page