Results 1 to 13 of 13

Thread: Producing a login in access

  1. #1
    Member
    Join Date
    Aug 2003
    Location
    South England
    Posts
    89
    Thanks
    0
    Thanked
    0 times in 0 posts

    Producing a login in access

    I am creating a database for college coursework. I am using a login system, where the user puts in their studentID found in the table student, and password found in the table student. I made a blank form and added the code

    If (Text1.Text = student![StudentID]) And (Text2.Text = student![Password]) Then

    MsgBox ("test")
    Else: MsgBox ("failed")
    End If

    To a command button.

    This isn't working because i presume I need to make it loop thru studentID until it = what is in text1 and the same with password.

    Any ideas how to do such a thing? All I need is it to extract the data from the table, compare the 2 sets of data, if it is true then msgbox("working") if it is false msgbox("Not working")

    Thanks

    Will

  2. #2
    Member
    Join Date
    Jul 2003
    Posts
    103
    Thanks
    0
    Thanked
    0 times in 0 posts
    i made a php login script for a school project last year, when i get home ill see if i can find the code

  3. #3
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    Try using Dlookup(Fieldname, TableName, Conditions)

    The snippet below works fine for me.

    Dim vFound As Variant
    vFound = DLookup("Student", "Students", "Student='martin' AND Password='1234'")

    If IsNull(vFound) Then
    MsgBox ("Username or password incorrect")
    Else
    MsgBox ("User login successul")
    End If


    Don't forget to put the ' ' marks around the user name and password. You would need to use...

    vFound = DLookup("Student", "Students", "Student='" & Text1.Text & "' AND Password='" & Text2.Text & "'")
    Last edited by Mart; 01-12-2003 at 01:44 PM.

  4. #4
    Member
    Join Date
    Aug 2003
    Location
    South England
    Posts
    89
    Thanks
    0
    Thanked
    0 times in 0 posts
    This doesn't seem to work, It says it cannot find the object Student.

  5. #5
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    You have different field + table names to my example.

    You need to use...

    vFound = DLookup("studentID", "student", "studentID='" & Text1.Text & "' AND Password='" & Text2.Text & "'")

  6. #6
    Member
    Join Date
    Aug 2003
    Location
    South England
    Posts
    89
    Thanks
    0
    Thanked
    0 times in 0 posts
    Yes I took that into account, but still produces error saying It cannot find object. Do I need to tell the form the object source? or is this done using dlookup?

  7. #7
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    In my example 'student' is the name of the table that contains the user name and password. If this name is incorrect or the field name is incorrect you will get the "can't find object error".

    If it still doesn't work try something simpler like just looking for a hard coded user name as below.

    vFound = DLookup("studentID", "students", "studentID='martin'")

    Once you get this working just add the AND clause.

    For my test all I did was create a new database with a single table (Students). In that table I added Student and Password fields both of type Text 50 characters long. I created a new form with a single button. In the button click event handler for the button I had the code above.

    Might be worth throwing together a test db recreating my steps.
    Last edited by Mart; 01-12-2003 at 05:11 PM.

  8. #8
    Member
    Join Date
    Aug 2003
    Location
    South England
    Posts
    89
    Thanks
    0
    Thanked
    0 times in 0 posts
    Right thanks for the help. I will give it ago tomorrow as I need to do some other work now. I shall post what I find

  9. #9
    Member
    Join Date
    Aug 2003
    Location
    South England
    Posts
    89
    Thanks
    0
    Thanked
    0 times in 0 posts
    It now gives me focus required. But if I do text1.setfocus before that line of code, it doesn't work. Do i need to set focus on text1 and text2 within

    vFound = DLookup("Student", "Students", "Student='" & Text1.Text & "' AND Password='" & Text2.Text & "'")

    Thanks

    I am now using yours as an example, just to test.

  10. #10
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    I forgot about this....

    You can only use the Text property of a textbox whilst it has the focus. When a textbox loses its focus it copies the Text data to the Value property.

    When the user clicks the button you don't know which control will have the focus. What you could do is add a line of code to set the focus to a specific control (not textboxes in question) and then use the Value properties of the textboxes with no problems.

  11. #11
    Member
    Join Date
    Aug 2003
    Location
    South England
    Posts
    89
    Thanks
    0
    Thanked
    0 times in 0 posts
    Right well I have fiddled for days now. I have got it working easily with either just username or just password, but I cannot get it working with both as it needs a focus. I don't see how you can add a focus half way thru a line of code?

    Text1.SetFocus
    vFound = DLookup("Student", "Student", "StudentID='" & Text1.Text & "'")

    This works fine, but to add the password area, how can I add focus half way thru to text2.text?

    Thanks

    Will

  12. #12
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    If you still want to use the Text property you need to copy it into a temporary variable...

    Dim strName As String
    Dim strPassword As String

    Text1.SetFocus
    strName = Text1.Text

    Text2.SetFocus
    strPassword = Text2.Text

    vFound = DLookup("Student", "Students", "Student='" & strName & "' AND Password='" & strPassword & "'")

  13. #13
    Member
    Join Date
    Aug 2003
    Location
    South England
    Posts
    89
    Thanks
    0
    Thanked
    0 times in 0 posts
    Thanks for the help Mart. Got it all working, now onto the next project

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •