+ Reply to Thread
Results 1 to 11 of 11

Entering Correct Username Displays Colour

Hybrid View

  1. #1
    Registered User
    Join Date
    04-07-2007
    Posts
    8

    Entering Correct Username Displays Colour

    Hi i have a username and password textbox and i want to know when i enter a correct username the textbox it is in turns green and when wrong it will turn red, here is the code i have so far im not very experienced but know bits and pieces.

    Code for txtpassword.text

    If Sheets("Admin Sheet").Range("B3") = tryPassword Then
        txtPassword.BackColor = vbGreen
        Else: txtPassword.BackColor = vbRed
            
        End If
    End Sub
    Code for txtusername.text

     If Sheets("Admin Sheet").Range("A2") = tryUserName Then
        txtUsername.BackColor = vbGreen
        Else: txtPassword.BackColor = vbRed
            
        End If
    End Sub
    any help would be brill thanks.
    Last edited by lvlister2005; 04-11-2007 at 02:12 PM.

  2. #2
    Registered User
    Join Date
    04-07-2007
    Posts
    8
    Please someone must know.

  3. #3
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Are the text boxes attached to the sheet, or on a user form? Also, what type of text boxes are they (inserted from forms toolbar, controls toolbar, or picture toolbar)?

  4. #4
    Registered User
    Join Date
    04-07-2007
    Posts
    8
    They are on a user form and they have been inserted suing the insert menu in the developer section in excel 2007.

  5. #5
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    In which event handler procedure is this code written? Try this:
    Private Sub txtPassword_Change()
        
        Dim tryPassword As String
        tryPassword = Me.txtPassword
        
        If Sheets("Admin Sheet").Range("B3") = tryPassword Then
            txtPassword.BackColor = vbGreen
        Else: txtPassword.BackColor = vbRed
        End If
        
    End Sub
    
    Private Sub txtUsername_Change()
        
        Dim tryUserName As String
        tryUserName = Me.txtUsername
        
        If Sheets("Admin Sheet").Range("A2") = tryUserName Then
            txtUsername.BackColor = vbGreen
        Else: txtUsername.BackColor = vbRed
        End If
        
    End Sub
    HTH

    Jason
    Last edited by jasoncw; 04-11-2007 at 06:37 PM.

  6. #6
    Registered User
    Join Date
    04-07-2007
    Posts
    8
    Thank you worked like a treat 1 final thing i was wondering how do you make the the first letter of a username be forced to be uppercase using the code you provided thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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