Verifying Logging on in a form

Posted on 2003-03-12
Medium Priority
Last Modified: 2008-03-06

I have a table with two cols- Username and Password.

I created a form with two fields - Username and Password and added a login button.

How do i get my button to check that what has been entered in the Username and Password fields is the same as what is held in my table, and then if okay carry out opening a form/s depending on what user level you are, and if not valid produce an error message.

It doesn't have to be highly secure but is just a means for limiting what is seen by different people.

Any help much appreciated.

Question by:Alli101
  • 2

Expert Comment

ID: 8118651
You can use this:

The Username is in a combo (cmbUserName) box with 2 columns (the second is of 0cm width)

The Password is entered in txtPWord.

    If Me.txtPWord = Me.cmbUserName.Column(1) Then
        ' Valid PWord
        MsgBox "Incorrect Password", vbExclamation
    End If

Not super secure, but works.

Hope it helps.
LVL 59
ID: 8118995
Below is the function I use to check my logins.  Should help get you started.


' FUNCTION: FValidUser
' PURPOSE:  Return true if the user is valid
Function FValidUser(UserName As Variant, Pwd As Variant) As Integer
    Dim db As Database
    Dim rstUsers As Recordset
    Dim FUserExists As Integer
    Dim strName As String
    Dim strPassword As String

    Const Routine = "FValidUser"
    Const Version = "1.1.0"

    On Error GoTo FValidUserError
    FValidUser = False
    strName = Nz(UserName, "")
    strPassword = Nz(Pwd, "")

    Set db = CurrentDb()
    Set rstUsers = db.OpenRecordset("qrysysValidUser")
    If rstUsers.RecordCount > 0 Then
      Do Until rstUsers.EOF
        If strName = rstUsers!UserName And strPassword = rstUsers!Password Then
          FValidUser = True
          Exit Do
        End If
    End If

    If Not rstUsers Is Nothing Then rstUsers.Close
    Set rstUsers = Nothing
    Set db = Nothing

    Exit Function

    UnexpectedError ModuleName, Routine, Version, Err, Error
    FValidUser = False
    Resume FValidUserExit

End Function

Accepted Solution

IanWorcester earned 200 total points
ID: 8119029
I didn't mention, but the combo box should be fed from a query where the first column is Username and the second column is the password. Therefore the uname and password are contained in the same row of the combo box and the password can be referrenced once a username has been selected. This allows the correct password to be retreived for the correct user without having to open a recordset in code.

Author Comment

ID: 8119299
Thankyou- worked a dream!

Thanks to everyone who responded.

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
A quick solution showing how to control and open a POS Cash Register Drawer using VBA with MS Access.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question