Results 1 to 4 of 4

Error in userform code

Threaded View

Sanjibghosh Error in userform code 04-05-2017, 06:35 AM
kev_ Re: Error in userform code 04-05-2017, 06:43 AM
Sanjibghosh Re: Error in userform code 04-05-2017, 06:54 AM
kev_ Re: Error in userform code 04-05-2017, 06:59 AM
  1. #1
    Forum Contributor
    Join Date
    07-15-2015
    Location
    Kolkata
    MS-Off Ver
    2010 & 2013
    Posts
    303

    Error in userform code

    Hi,

    I want to create a login userform and i have made it. But i am getting an error. Any one help me how to resolve the error.

    Public Username As String
    Public Password As String
    Public i As Integer
    Public j As Integer
    Public u As String
    Public p As String
      
    Private Sub CommandButton1_Click()
        Application.ScreenUpdating = False
        If Trim(TextBox1.Text) = "" And Trim(TextBox2.Text) = "" Then
            MsgBox "Enter username and password.", vbOKOnly
            Else If Trim (me.TextBox1.Text) = "" Then
            MsgBox "Enter the username ", vbOKOnly
            Else If Trim(TextBox2.Text) = "" Then
            MsgBox "Enter the Password ", vbOKOnly
        Else
            Username = Trim(TextBox1.Text)
            Password = Trim(TextBox2.Text)
            i = 1
            Do While Cells(1, 1).Value <> ""
                j = 1
                u = Cells(i, j).Value
                j = j + 1
                p = Cells(i, j).Value
                If Username = u And Password = p And Cells(i, 3).Value = "fail" Then
                    MsgBox "Your Account temporarily locked", vbCritical
                    Exit Do
                    Else If Username = u And Password = p Then
                    Call clear
                    UserForm1.Hide
                    UserForm2.Label1.Caption = u
                    UserForm2.Label1.ForeColor = &H8000000D
                    UserForm2.Show
                    Exit Do
                    Else If Username <> u And Password = p Then
                    MsgBox "Username not matched", vbCritical + vbOKCancel
                    Exit Do
                    Else If Username = u And Password <> p Then
                    If Cells(i, 3).Value = "fail" Then
                        MsgBox "Your account is blocked", vbCritical + vbOKCancel
                        Exit Do
                        Else If Cells (i, 4).Value < 2 Then
                        MsgBox "Invalid password", vbCritical
                        Cells(i, 4).Value = Cells(i, 4) + 1
                        Exit Do
                    Else
                        Cells(i, 4).Value = Cells(i, 4) + 1
                        Cells(i, 3).Value = "fail"
                        Cells(i, 2).Interior.ColorIndex = 3
                        Exit Do
                    End If
                Else
                    i = i + 1
                End If
            Loop
        End If
        Application.ScreenUpdating = True
        
    End Sub
    Sub clear()
        TextBox1.Value = ""
        TextBox2.Value = ""
    End Sub
    Private Sub TextBox1_Enter()
        With TextBox1
            .Back Color = &H8000000E
            .Fore Color = &H80000001
            .Border Color = &H8000000D
        End With
        TextBox1.Text = ""
    End Sub
    Private Sub TextBox1_AfterUpdate()
        If TextBox1.Value = "" Then
            TextBox1.BorderColor = RGB(255, 102, 0)
        End If
        i = 1
        Do Until Is Empty (Cells (i, 1).Value)
            If TextBox1.Value = Cells(i, 1).Value Then
                With TextBox1
                    .Border Color = RGB(186, 214, 150)
                    .Back Color = RGB(216, 241, 211)
                    .Fore Color = RGB(81, 99, 51)
                End With
            End If
            i = i + 1
        Loop
    End Sub
    Private Sub TextBox2_Enter()
        With TextBox2
            .Back Color = &H8000000E
            .Fore Color = &H80000001
            .Border Color = &H8000000D
        End With
        TextBox2.Text = ""
    End Sub
    Private Sub TextBox2_AfterUpdate()
        i = 1
        Username = TextBox1.Value
        Password = TextBox2.Value
        If TextBox2.Text = "" Then
            TextBox2.BorderColor = RGB(255, 102, 0)
        End If
        Do Until Is Empty (Cells (i, 1).Value)
            j = 1
            u = Cells(i, j).Value
            j = j + 1
            p = Cells(i, j).Value
            If Username = u And Password = p Then
                With TextBox2
                    .Border Color = RGB(186, 214, 150)
                    .Back Color = RGB(216, 241, 211)
                    .Fore Color = RGB(81, 99, 51)
                End With
                Exit Do
                Else If Username = u and Password <> p Then
                TextBox2.BorderColor = RGB(255, 102, 0)
                Exit Do
            Else
                i = i + 1
            End If
        Loop
    End Sub
    Sub settings()
        With UserForm1
            TextBox1.ForeColor = &H8000000C
            TextBox2.ForeColor = &H8000000C
            TextBox1.BackColor = &H80000004
            TextBox2.BackColor = &H80000004
            TextBox1.Text = "Username"
            TextBox2.Text = "Password"
            TextBox1.BorderColor = RGB(0, 191, 255)
            TextBox2.BorderColor = RGB(0, 191, 255)
            CommandButton1.SetFocus
        End With
    End Sub
    Private Sub UserForm_Initialize()
        Call settings
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Code producing error, only on third run of Userform...?
    By RayJay01 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-12-2019, 10:01 PM
  2. VBA userform problem with code (syntax error)
    By Odowd in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-27-2016, 09:23 PM
  3. Help with userform code looping and bringing error
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-11-2015, 06:02 AM
  4. Need someone to look over my userform code as i keep getting error 361 for no reason
    By uglymaggot in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-17-2014, 10:31 AM
  5. VBA code error for userform dependent combobox
    By Jonno1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-29-2014, 01:35 PM
  6. [SOLVED] Code Produces Error When Trying to Operate a Particular Userform after Another
    By JP777 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-29-2012, 08:04 PM
  7. UserForm Code Error
    By Mooseman60 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2010, 09:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1