Hello guys. I'm new here. Can you help me with this?
These are the codes in the first form. My problem is that it runs and connects to the MSAccess. But the problem is. Only the first record in MSAccess is allowed.
UserName Password
1100178 admin this is the only part that allows the user to enter the program. the rest is not applicable. can anyone help me to allow the other record to be the alternative username and password?
1100128 admin
1100237 admin
1100016 admin
1100055 admin
Option Explicit
Dim db As Database
Dim rs As Recordset
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdOK_Click()
If txtUserName.Text = rs!UserName And txtPassword.Text = rs!Password Then
Form1.Show
frmLogin.Hide
Else
MsgBox "Invalid Username/Password", vbCritical, "Try Again!"
txtUserName.Text = ""
txtPassword.Text = ""
txtUserName.SetFocus
End If
End Sub
Private Sub Form_Load()
Set db = OpenDatabase("C:\vb\Access\Database.mdb")
Set rs = db.OpenRecordset("Account")
End Sub
Only the first row is read by the program
-
- Lounger
- Posts: 38
- Joined: 03 Feb 2013, 15:23
Only the first row is read by the program
Student here.
Johann/Yuwan
Johann/Yuwan
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Only the first row is read by the program
Welcome to Eileen's Lounge! Try this version:
Code: Select all
Option Explicit
Dim db As DAO.Database
Dim rs As DAO.Recordset
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
rs.FindFirst "UserName='" & Me.txtUserName & "' AND Password='" & Me.txtPassword & "'"
If rs.NoMatch Then
Me.txtUserName.Text = ""
Me.txtPassword.Text = ""
Me.txtUserName.SetFocus
MsgBox "Invalid Username/Password", vbCritical, "Try Again!"
Else
Form1.Show
Me.Hide
End If
End Sub
Private Sub Form_Load()
Set db = OpenDatabase("C:\vb\Access\Database.mdb")
Set rs = db.OpenRecordset("Account", dbOpenDynaset)
End Sub
Best wishes,
Hans
Hans
-
- Lounger
- Posts: 38
- Joined: 03 Feb 2013, 15:23
Re: Only the first row is read by the program
It's fine now. Thanks. =D. Our professor helped us. Thanks also for answering =D
Student here.
Johann/Yuwan
Johann/Yuwan