How to call fields from Access with VB 4.0

What I'm trying to do is use VB to create a password program that verifies what has been entered in the text boxes against fields in an Access database ie username and password. Is this possible and if so how do I go about it?
Reaper_38Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Reaper_38Author Commented:
Please answer ASAP as I need to know for my course project
0
tkuppinenCommented:
This is a very basic procedure I used for a similar course project.  I have better ones available but this one suits your basic needs.


'============
'   This procedure verfies that the user name and password and username
'   texboxes are valid entries for the system
'
'
'
'============
On Error GoTo errhandler

Dim rsLogin As Recordset, strLogin As String

Set rsLogin = New Recordset

strLogin = "select * from employees where password = '" & TranslateSQL(txtPassword.Text) & "' and user_id ='" & TranslateSQL(txtUserName.Text) & "'"

' open database
cnLogin.Open ("aps_test")

' Debug.Print cnLogin.Attributes
' fill recordset, if there is no user with that combination of
' user name and password, we will generate an error and therfore it is
' incorrect

Set rsLogin = cnLogin.Execute(strLogin)
' fill global variables for use throughout the application
intEmpId = rsLogin("id")
strEmpName = rsLogin("f_name") & " " & rsLogin("l_name")
strSprName = rsLogin("emp_sprvsr")
minDate = rsLogin("hireDate")

cnLogin.Close

Set rsLogin = Nothing

checkLogin = True

errhandler:
Select Case Err.Number
Case 0, 20
Resume Next
Case Else
' invalid entry causing no records to be returned
MsgBox "Invalid username or password please try again."
txtPassword.SetFocus
SendKeys "{Home}+{End}"
checkLogin = False
'cnLogin.Close
End Select
0
tkuppinenCommented:
This relies on you having referenced ADO and declared command and connection object variables.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Reaper_38Author Commented:
I will say now that my knowledge of VB is very limited so notes to go with any code would be much appreciated
0
tkuppinenCommented:
Let me know specifically what you need help with.
0
Reaper_38Author Commented:
I have made a db in Access called CollegeSec and within that is a table called Computer Login. In this table are two fields, ID Number and Password. I have five users in this db

What I want to do is to verify that what the user inputs into Text1 (for ID Number) and Text2 (Password) corresponds with the information inputted for one of my users
0
rondeaujCommented:
dim db as database
dim rs as recordset
dim found as boolean

set db = opendatabase(filename)
set rs = db.openrecordset(tablename)

'now find your user
if rs.recordcount =>1 then
   do while not rs.eof
       if rs!user = txtuser and rs!password = txtpassword then
           found = true
           exit do
   loop
rs.close
db.close

if not found then
  msgbox "Incorrect Password"
end if
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rondeaujCommented:
add this line before Loop statement

   rs.movenext
0
rondeaujCommented:
Also forgot end if's

HEHE
0
rondeaujCommented:
The above example will also check for correct case. If you don't care if the user has entered lower or upper case you can convert:

replace this line:

if rs!user = txtuser and rs!password = txtpassword then
           

with this line:

if ucase$(rs!user) = ucase$(txtuser) and ucase$(rs!password) = ucase$(txtpassword) then
           
Where Ucase$() converts the string you uppercase.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.