3 Replies - 2374 Views - Last Post: 16 March 2013 - 06:47 AM Rate Topic: -----

#1 daimegaera  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 17-September 10

What is wrong with my code?

Posted 16 March 2013 - 03:54 AM

i have a main form with two buttons HR and TR and a login form with two login buttons containing two different codes for login. One is to show the HR_Main form if log in is success and another for the TR_main form. I want my Admin to be able to access both forms when logged in where the username and password is in a different table. The log in button for HR Login is working just fine but when i try to do it for the TR_Login i get a msg of "Invalid Password" even if i enter the correct username and password.

Login button code for HR:



  Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hrLogin.Click
        frmMain.NameToolStripMenuItem.Text = TextBox1.Text
        Dim hrManager As New HR_DatabaseManager()    'Class form name
        Dim adminManager As New Admin_DatabaseManager  ' Class form name

'checks if the user exist in HR Table
        If CBool(hrManager.Login(TextBox1.Text, TextBox2.Text)) Then
            MsgBox("Welcome to HR Department " & TextBox1.Text, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, TextBox1.Text)
            Me.Close()
            frmMain.Show()
        Else
            MsgBox("Invalid Username or Password", MsgBoxStyle.Critical, "Please check your username or password")
        End If
'checks if the user exist in the Admin table
        If TextBox1.Text = "Admin" Or TextBox1.Text = "admin" Then
            hrAdmin() ' name of my private sub that contains the code for checking if the data exist in the admin table

        End If


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    



Login button Code for TR:
  frmMain.NameToolStripMenuItem.Text = TextBox1.Text
        Dim hrManager As New HR_DatabaseManager()    'Class form name
        Dim adminManager As New Admin_DatabaseManager  ' Class form name

'checks if the user exist in TR Table
        If CBool(hrManager.Login(TextBox1.Text, TextBox2.Text)) Then
            MsgBox("Welcome to HR Department " & TextBox1.Text, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, TextBox1.Text)
            Me.Close()
            frmMain.Show()
        Else
            MsgBox("Invalid Username or Password", MsgBoxStyle.Critical, "Please check your username or password")
        End If
'checks if the user exist in the Admin table
        If TextBox1.Text = "Admin" Or TextBox1.Text = "admin" Then
            trAdmin() ' name of my private sub that contains the code for checking if the data exist in the admin table

        End If




Is This A Good Question/Topic? 0
  • +

Replies To: What is wrong with my code?

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,876
  • Joined: 12-December 12

Re: What is wrong with my code?

Posted 16 March 2013 - 05:51 AM

Your code looks identical/parallel for hr and tr, except that you are using hrManager.Login() in both instances(?).
Was This Post Helpful? 0
  • +
  • -

#3 daimegaera  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 17-September 10

Re: What is wrong with my code?

Posted 16 March 2013 - 06:22 AM

View Postandrewsw, on 16 March 2013 - 05:51 AM, said:

Your code looks identical/parallel for hr and tr, except that you are using hrManager.Login() in both instances(?).


yeah they are the same but only the login button for hr is working and but for the TR log in button it doesn't work

BTW here is the code under trAdmin() and hrAdmin (), the only difference of this two is the form that will show up if the log in is successful.

Private Sub trAdmin()
        frmMain.NameToolStripMenuItem.Text = TextBox1.Text
        Dim adminManager As New Admin_DatabaseManager()

        If CBool(adminManager.Login(TextBox2.Text)) Then
            MsgBox("Welcome to TR Department " & TextBox1.Text, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, TextBox1.Text)
            Me.Close()
            record2.Show()
        Else
            MsgBox("Invalid Username or Password", MsgBoxStyle.Critical, "Please check your username or password")
        End If
    End Sub


Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,876
  • Joined: 12-December 12

Re: What is wrong with my code?

Posted 16 March 2013 - 06:47 AM

Your code lacks clarity (for want of a better phrase) and I find it hard to follow.

I suggest you read the debugging tutorial linked in my signature, so that you can step-through your code and discover where it goes wrong.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1