• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

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?
0
Reaper_38
Asked:
Reaper_38
  • 4
  • 3
  • 3
1 Solution
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now