VB6, code refer to access database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sorin
    New Member
    • Feb 2021
    • 1

    VB6, code refer to access database

    Hi, want to ask the following

    if rs.fields(0).va lue=text1.text and rs.fields(1).va lue=text2.text then
    mainform.show
    loginform.hide

    As you know, above code is part of Login processing. There are two text boxes for user name and password entry. Number (0) and (1) (in above code) refers to access database fields that user names and passwords are stored there. above code works fine for one user only.

    Wondering, how to set for more users and how to extend this code so that anyone whose name,pass is in db, can access to main form. I tried adding fields in db for more usernames but from login form could not refer to them either by field number or data type so, not responding positively.
    Thanks in advance
  • MerlinTheGreat
    New Member
    • Jun 2022
    • 6

    #2
    Depending on how many users you have, you can either run through every record of the database table and do the check the way you do in your example, or use a SQL statement to find the username and if found check the password.

    Sequentially running through the records until the last, you probably know how to do.
    For SQL statements you might have to install an additional database driver to acces the Access database.
    SQL is much easier to get and put data into the database.

    In SQL you'll use something like this:
    Code:
    SELECT * FROM [Database.Table] WHERE [Table.UserName] EQ Text1.Text
    If [Table.Password] = Text2.Text then
      mainform.show
      loginform.hide
    End If
    If there are more fields in the table than username and password, you can replace the asterisk (*) with the required fieldnames separated by a comma. That way only the listed fields will be loaded.
    An asterisk loads all fields of the table.

    Hope this gets you started.

    Comment

    Working...