Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7680115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:02:15+00:00 2026-05-31T18:02:15+00:00

Private Sub cmdLogin_Click() On Error GoTo ErrorHandler Dim RowNo As Long Dim Id As

  • 0
Private Sub cmdLogin_Click()
On Error GoTo ErrorHandler

Dim RowNo As Long
Dim Id As String
Dim pw As String
Dim ws As Worksheets

Application.ScreenUpdating = False
Set ws = Worksheets("User&Pass")
Id = LCase(Me.txtLogin)


RowNo = Application.WorksheetFunction.Match(Id, ws.range("A2:A999"), 0)

CleanExit:
Set ws = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
Exit Sub

ErrorHandler:
MsgBox "Unable to match ID, enter valid ID.", vbOKOnly 
GoTo CleanExit

End Sub

I’ve got an excel userform i’ve been working on and now I need it to look more professional by having a log-in screen. I’ve started with the code above but I have come to a dead end.

how its set up my aim is to say if id & password matches then load up workbook or unhide the workbook and continue. the username and password are on a sheet called “User&Pass”
Aim is it reads from there in columns a- user / b- pw respectively and if it’s a success I will hide that sheet so they cant see other user’s information

with what I started above I just need it to say if it matches usercolumn then corresponding pw next door to it continue else go to my errorhandler

i can do the formatting about hiding and unhiding sheets etc just need help with reading username and pw

thanks very much in advance
Z

Editted attempt one;

Private Sub cmdLogin_Click()
On Error GoTo ErrorHandler
Dim RowNo As Long
Dim Id As String
Dim pw As String
Dim ws As Worksheets
Application.ScreenUpdating = False
Set ws = Worksheets("User&Pass")

Id = LCase(Me.txtLogin)
RowNo = Application.WorksheetFunction.Match(Id, ws.range("A2:A999"), 0)
RowNo = RowNo + 1
pw = ws.range("B" & RowNo)
If pw = Me.txtLogin Then
'continue
txt1.Value = "yes"
Else
GoTo ErrorHandler
End If


CleanExit:
Set ws = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
Exit Sub
ErrorHandler:
MsgBox "Unable to match ID, enter valid ID.", vbOKOnly
GoTo CleanExit
End Sub

@siddarthRout

Private Sub cmdLogin_Click()
Dim RowNo As Long
Dim Id As String, pw As String
Dim ws As Worksheet
Dim aCell As range
On Error GoTo ErrorHandler
Application.ScreenUpdating = True

Set ws = Worksheets("Details")
Id = LCase(Me.txtLogin)

Set aCell = ws.Columns(1).Find(What:=Id, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

'~~> If match found
If Not aCell Is Nothing Then
RowNo = aCell.Row
'~~> Rest of your code. For example if the password is
'~~> Stored in Col B then
Debug.Print aCell.Offset(, 1)
Unload Me
FrmMenu.Show
'~~> You can then use the above aCell.Offset(, 1) to
'~~> match the password which the user entered
Else '<~~ If not found
MsgBox "Unable to match ID, enter valid ID.", vbOKOnly
End If
CleanExit:
Set ws = Nothing
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox Err.Description
Resume CleanExit
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:02:17+00:00Added an answer on May 31, 2026 at 6:02 pm

    TESTED AND TRIED

    Is this what you are trying?

    CODE

    Option Explicit
    
    Private Sub cmdLogin_Click()
        Dim RowNo As Long
        Dim Id As String, pw As String
        Dim ws As Worksheet
        Dim aCell As Range
    
        On Error GoTo ErrorHandler
    
        If Len(Trim(txtLogin)) = 0 Then
            txtLogin.SetFocus
            MsgBox "Username cannot be empty"
            Exit Sub
        End If
    
        If Len(Trim(txtPassword)) = 0 Then
            txtPassword.SetFocus
            MsgBox "Password cannot be empty"
            Exit Sub
        End If
    
        Application.ScreenUpdating = False
    
        Set ws = Worksheets("User&Pass")
        Id = LCase(Me.txtLogin)
    
        Set aCell = ws.Columns(1).Find(What:=Id, LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
    
        '~~> If match found
        If Not aCell Is Nothing Then
            RowNo = aCell.Row
            If Me.txtPassword = aCell.Offset(, 1) Then
                FrmMenu.Show
                Unload Me
            Else
                MsgBox "Unable to match UserID or PasswordID, Please try again", vbOKOnly
            End If
        Else '<~~ If not found
            MsgBox "Unable to match UserID or PasswordID, Please try again", vbOKOnly
        End If
    CleanExit:
        Set ws = Nothing
        Application.ScreenUpdating = True
        Exit Sub
    ErrorHandler:
        MsgBox Err.Description
        Resume CleanExit
    End Sub
    

    TIP:

    Never let your user know (from security perspective) what was incorrect – The username or the password. Always show a generic message like “Unable to match UserID or PasswordID, Please try again” 🙂

    HTH

    Sid

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey here is my script: Private Sub UpdateThread() Dim AppDir As String = Application.StartupPath()
Here is my code: Dim StartString As String = Private Sub Dim EndString As
Heres my sub: Dim onThisTable as String =Name Private Sub skill_mouseHover(ByVal sender As System.Object,
Private Sub hideHeadings() Dim obj As Window For Each obj In Application.Windows obj.DisplayHeadings =
Private Sub Command1_Click() Dim x As Integer For x = 1 To 100 List1.AddItem
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Dim allowedChars
Private Sub Command1_Click() Dim dom As New DOMDocument Dim http As New XMLHTTP Dim
Using the following code: Private Sub MakeMeSomeXmlBeforeRyanGetsAngry() Dim db As New MyDBDataContext Dim customer
I have the following code: Private Sub SortWorksheet(ByVal sheet As Worksheet) Dim sStartColumn Dim
I frequently encounter this situation in my VB6 applications Private Sub DoSomething On Error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.