Start New Discussion within our Software Development Community

Can someone help me to create a login screen. I am new to VB and don't know how to proceed with.
I have VB 6.0 and MS-Access 2003 and Ms-Access 2007.

I have a form with 2 textbox(userid & password)
2 buttons (Login and Exit)
A database with name Login.mdb (table name: tbllogin)

I wish to write a code which will help the user only if his or her user id and password exist in the database. If wrong input is given it should not allow the user to go to next form.

Private Sub Form_Load()
On Error Resume Next
SetAttr (App.path & "\Company.mdb"), vbNormal
Set db1 = OpenDatabase(App.path & "\Company.mdb")
Set User = db1.OpenRecordset("Select * From User")
End Sub
Private Sub ok_Click()
On Error Resume Next
If txtlogin.Text = "" Or txtpass.Text = "" Then
    MsgBox "Please Enter Correct User ID.", vbInformation
    txtlogin.SetFocus
    Exit Sub
End If
User.FindFirst "UserID='" & Trim(txtlogin.Text) & "' and UserPass='" & Trim(txtpass.Text) & "'"
If User.NoMatch Then
    MsgBox "Please Enter Correct User Password.", vbInformation
    txtpass.SetFocus
    Exit Sub
Else
  Set User = db.OpenRecordset("Select * From User")
  If User.RecordCount <> 0 Then User.MoveFirst
    Do While Not User.EOF = True
      If UCase(User!UserID) = UCase(Trim(txtlogin.Text)) Then
          If User!Login <> 0 Then
            RA = User!RA: RM = User!RM: RD = User!RD
            RP = User!RP: RR = User!RR: RT = User!RT
            UType = User!Type: UserID = User!UserID: Usr = User!Sno
            Unload Login: Menu.Show: Exit Sub
          Else
            MsgBox "Permission Denided. Please contact your Administrator.", vbCritical + vbOKOnly, "Permission"
            End
          End If
      End If
      User.MoveNext
    Loop
End If
End Sub

here I use my code. you can modify with some change, like table name etc.

This article has been dead for over six months. Start a new discussion instead.