Hi
I have a 3 userforms and 3 worksheets userform1 is the main form. what I want to happen is when workbook is opened user is presented with a login screen (userform3) they enter their username and password and then userform3 is hidden and userform1 opens .Within userform1 is a textbox (textbox10) i want the details entered to display in textbox10 and remain there as a running log of who logged in and when these details will also be recorded on sheet3 in columns A2(User) and B2 (Password) my code is below but does not work nothing goes into the textbox nor sheet 3. The code does not throw up any errors .Can anyone spot any errors ,
Dim user As String
Dim password As String
Dim loginTime As String
user = Me.txtuserid.Value
password = Me.txtpassword.Value
'check if username and password are correct
If (user = "philp" And password = "et") Or (user = "Luml" And password = "et") Then
'store current date and time
loginTime = Format(Now(), "dd-MM-yyyy hh:mm:ss")
'hide Userform3 if it's open
If UserForm3.Visible = True Then
UserForm3.Hide
End If
'show Userform1 and add login information to textbox
UserForm1.Show
UserForm1.TextBox10.Value = ""
UserForm1.TextBox10.Value = user & " logged in at " & loginTime
'append login information to a log file or worksheet
Dim loginArray As Variant
loginArray = Worksheets("sheet3").Range("A2:b2").Value
For i = 1 To UBound(loginArray)
UserForm1.TextBox10.Value = UserForm1.TextBox10.Value & loginArray(i, 1) & " logged in at " & loginArray(i, 2) & vbNewLine
Next i
Else
'display error message
MsgBox "Your username or password is incorrect", vbOKOnly + vbCritical, "Invalid credentials!"
End If
End Sub
Bookmarks