Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a username and password to log on

Status
Not open for further replies.

dsmart16

IS-IT--Management
Joined
Nov 30, 2004
Messages
12
Location
CA
Help,

Hi there, I'd like to setup my database to have a username and password as the opening screen. Once the user enters a proper username and password they will then allow them in and to specific information.

I have created a table that stores the Username, Password, and the UserType (UserType will determine whether the user has Full rights, forms and reports, or reports only)

I then have a form called frmLogon. On this form I have txtUsername, txtPassword, cmdLogon, and cmdExitDatabase.

I want the user to enter their username and password, click on LogOn

the on click event will then check to make sure that the username and password match up to the username and password in the table

then setting the usertype according to what was assigned to the user in the table.

anyhow, I know there's a bit here, but if anyone can help it'd be greatly appreciated. Any questions please let me know.
 
Hi there, this is how I would do it, You've already got the form / table etc so all you need is to add the following code to the On_Click event for cmdLogOn....

Code:
Private Sub cmdLogOn_Click()

Dim Found As Boolean
Dim dbcurr As Database
Dim tblUserDetailrs As Recordset

Set dbcurr = Workspaces(0).Databases(0)
Set tblUserDetailrs = dbcurr.OpenRecordset("tblUserDetail")

Found = False

If IsNull(Me.txtUserName) Or IsNull(Me.txtPassword) Then
    MsgBox "Please enter both user name and passord"
    Exit Sub
End If

With tblUserDetailrs
    If .RecordCount = 0 Then
        MsgBox "No users in table!"
        Exit Sub
    End If
    
    .MoveFirst
    Do Until .EOF Or Found
        If .Fields!UserName = txtUserName Then
            If .Fields!Password = txtPassword Then
                Found = True
                'let the user into the database
            Else
                MsgBox "you have entered the wrong password"
                Exit Sub
            End If
        End If
        .MoveNext
    Loop
End With

If Not Found Then
    MsgBox "You are not a registered user"
End If

End Sub

Also, you can make your password look like this... ****** by setting the input mask property of txtPassword to 'PASSWORD' on the form.

Hope this helps

jimlad
 
Hi there--have you tried searching the forum? There are multiple posts regarding this topic!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top