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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login/Password Form through SQL table check

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm trying to make a simple form with login and password text boxes and a submit button. When I click on submit, it will run a SQL statement that will "SELECT * from table WHERE UserID = {name of textbox}"

First question....what would be the proper SQL statement to get the result. Second question, how do I write the correct code to make sure the login and password are correct. Because if they are correct, then I want the database to jump to the next form we have created.

Any help would greatly be appreciated.
 
Say your form has text boxes named txtUserName and txtPassword. Assuming you intend to use VBA code, I would use the following AfterUpdate event procedure for your Submit button:
Code:
    Private Sub cmdSubmit_AfterUpdate()
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Set db = CurrentDb()
        Set rst = db.OpenRecordset("SELECT * FROM table WHERE UserID = '" & Me!txtUserID & "' AND Password = '" & Me!txtPassword & "';"
        If rst.EOF Then
            Beep
            MsgBox "Invalid user ID or password."
        Else
            DoCmd.OpenForm ....
        End If
        rst.Close
        Set rst = Nothing
        Set db = Nothing
    End Sub
I have to wonder whether this security is just to keep unwelcome users out, but once in, everything is open to anybody. You didn't say anything about limiting the functions or data available to the user, based on information in your logon table. I'm not very confident of this form of security. It's really quite easy to get into an Access database and bypass your logon form, unless you've gone to a lot of trouble to block all the ways that can be done.

If all you want is a front door password, you might consider giving the database itself a password. It's easier and more secure.
Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top