Log in

erfe_23

New Member
Joined
Dec 8, 2011
Messages
9
Hi,

can any body help me with this one. i'm kinda new with vb in excel. i made this code for my log in form. the log in works if the information inputted is correct. i tried everything to pop up a prompt if the log in info does not match. but i failed. this my code:

Private Sub cmdOk_Click()
Dim i As Integer
Dim l As Integer
Dim j As Integer
Dim final As Integer
Dim msg As String



For i = 1 To 1000
If wrkUser.Cells(i, 1) = "" Then
final = i - 1
Exit For
End If
Next



For l = 1 To final

If wrkUser.Cells(l, 1) = txtUsername And wrkUser.Cells(l, 2) = txtPassword Then

wrkStart.cmdLock.Visible = True
wrkStart.cmdNew.Enabled = True
wrkStart.cmdEdit.Enabled = True
wrkStart.cmdStore.Enabled = True
wrkStart.cmdShow.Enabled = True

Unload Me

Exit For
End If
Next

End Sub


any solutions to this?
its going to be a huge help for me.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi,

Are you refering to below:


Hi,

can any body help me with this one. i'm kinda new with vb in excel. i made this code for my log in form. the log in works if the information inputted is correct. i tried everything to pop up a prompt if the log in info does not match. but i failed. this my code:

Private Sub cmdOk_Click()
Dim i As Integer
Dim l As Integer
Dim j As Integer
Dim final As Integer
Dim msg As String



For i = 1 To 1000
If wrkUser.Cells(i, 1) = "" Then
final = i - 1
Exit For
End If
Next



For l = 1 To final

If wrkUser.Cells(l, 1) = txtUsername And wrkUser.Cells(l, 2) = txtPassword Then

wrkStart.cmdLock.Visible = True
wrkStart.cmdNew.Enabled = True
wrkStart.cmdEdit.Enabled = True
wrkStart.cmdStore.Enabled = True
wrkStart.cmdShow.Enabled = True

Unload Me

Exit For
else
MsgBox "Error"
End If
Next

End Sub


any solutions to this?
its going to be a huge help for me.
 
Upvote 0
Hi,

Welcome to the board,

Please use Code tags for your VBA code

Below code might help you.

Code:
Private Sub cmdOk_Click()
    Dim i As Integer
    Dim l As Integer
    Dim j As Integer
    Dim final As Integer
    Dim msg As String
    
    For i = 1 To 1000
        If wrkUser.Cells(i, 1) = "" Then
            final = i - 1
            Exit For
        End If
    Next
    
    For l = 1 To final
        If wrkUser.Cells(l, 1) = txtUsername And wrkUser.Cells(l, 2) = txtPassword Then
            wrkStart.cmdLock.Visible = True
            wrkStart.cmdNew.Enabled = True
            wrkStart.cmdEdit.Enabled = True
            wrkStart.cmdStore.Enabled = True
            wrkStart.cmdShow.Enabled = True
            Unload Me
            Exit For
        Else
            MsgBox "Please Check your login information. Its not matching", vbCritical, "Login"
        End If
    Next
End Sub
 
Upvote 0
i tried but its not working. eventhough the information is correct it still pos up the msgbox message. i tried the Exit sub after the msgbox, but no luck.
 
Upvote 0
i tried but its not working. eventhough the information is correct it still pos up the msgbox message. i tried the Exit sub after the msgbox, but no luck.

If txtUsername and txtPassword is a text box then please try:

txtUsername .value and txtPassword.value

If wrkUser.Cells(l, 1) = txtUsername.value And wrkUser.Cells(l, 2) = txtPassword.value Then
 
Upvote 0
i tried the txt.value but still the same.


Thanks


Please try:

If wrkUser.Cells(l, 1).value = txtUsername.value And wrkUser.Cells(l, 2).value = txtPassword.value Then


If it is still not working then please help me to put the following code like below :
and records down what is the msgbox prompt.

Code:
Private Sub cmdOk_Click()
    Dim i As Integer
    Dim l As Integer
    Dim j As Integer
    Dim final As Integer
    Dim msg As String
 
    For i = 1 To 1000
        If wrkUser.Cells(i, 1) = "" Then
            final = i - 1
            Exit For
        End If
    Next
 
    For l = 1 To final
 
        If wrkUser.Cells(l, 1).value  = txtUsername.value  And wrkUser.Cells(l, 2).value = txtPassword.value  Then
            MsgBox "Check value " & txtUsername.value & " / Usercell is " & wrkUser.Cells(l, 1).value
            MsgBox "Check value " & txtPassword.value & " / Usercell is " & wrkUser.Cells(l, 2).value
 
            wrkStart.cmdLock.Visible = True
            wrkStart.cmdNew.Enabled = True
            wrkStart.cmdEdit.Enabled = True
            wrkStart.cmdStore.Enabled = True
            wrkStart.cmdShow.Enabled = True
            Unload Me
            Exit For
        Else
            MsgBox "Please Check your login information. Its not matching", vbCritical, "Login"
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top