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.
 
results:

Check value admin/Usercell admin

values are all correct but why does the MsgBox with error always pops up first?


Thanks
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Ok, :)

We should check this instead:

Code:
Else
MsgBox "Check value " & txtUsername.value & " / Usercell is " & wrkUser.Cells(l, 1).value
MsgBox "Check value " & txtPassword.value & " / Usercell is " & wrkUser.Cells(l, 2).value 
MsgBox "Please Check your login information. Its not matching", vbCritical, "Login"
End If
 
Upvote 0
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.value And wrkUser.Cells(l, 2) = txtPassword.value Then
 If wrkUser.Cells(l, 1).value = txtUsername.value And wrkUser.Cells(l, 2).value = txtPassword.value 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
'Exit Sub
Else
MsgBox "Check value " & txtUsername.value & " / Usercell is " & wrkUser.Cells(l, 1).value
MsgBox "Check value " & txtPassword.value & " / Usercell is " & wrkUser.Cells(l, 2).value
MsgBox "error"
'Exit For
'Exit Sub
End If
Next

End Sub

tried
still no luck. even with the correct value. msgbox "error" still comes out first then executes. with incorrect values msgbox "error" comes out but executes the loop with how many cells are populated. lets say the wrkuser has 3 username and 3 password. the msgbox"error" will come out 3 times.




thanks
 
Upvote 0
Check value admin/ Usercell value USERNAME

Check value admin/ Usercell value PASSWORD

Msgbox"Error"

repeats 4 times.


Thanks
 
Upvote 0
Hi,

From the message box. It seems like your cells value is username and password. These two cells' value were code to check again text box value.


I think you might need to change the value of the I. Example from 2 to final instead of 1 to final.
 
Upvote 0

Forum statistics

Threads
1,215,586
Messages
6,125,687
Members
449,249
Latest member
ExcelMA

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