I have a userform which is a username/password login form which validates a persons login details from a read-only spreadsheet based on a hidden worksheet ("Admin Users") in a 2nd spreadsheet. The coding for that is all working find however I am now trying to make it so that once it has verified that the username and password are valid, that it copies that persons authorities from the "Admin Users" worksheet into the 1st spreadsheet on a duplicate worksheet named "Temp Admin Users" so that the authorities can be referred to whilst they are still logged in.
I currently have the following code (edited as contains company details) but I can't seem to get it to do the copy/paste:
Thanks in advance.
I currently have the following code (edited as contains company details) but I can't seem to get it to do the copy/paste:
VBA Code:
Private Sub CMD_Login_Click()
'Ensures PIN is entered as 5 digits
If Len(TxtPIN.value) <> 5 Then
MsgBox "PIN must be 5 digits.", vbCritical
Exit Sub
End If
Set wbk = Workbooks.Open("\\****\Returns v.2.0.xlsx", ReadOnly:=True)
Dim targetSh As Worksheet ' NEW TEST CODE
Set targetSh = ThisWorkbook.Worksheets("Temp Admin Users") ' NEW TEST CODE
UserName = TxtPIN.value
PW = TxtPassword.value
Set rngUser = wbk.Sheets("Admin Users").Range("A:B").Find(UserName, , , xlWhole, , , False, , False)
If Not rngUser Is Nothing Then
If (PW = rngUser.Offset(0, 1).value) And rngUser.Offset(0, 11).value = "Yes" Then
TxtUsers.Text = wbk.Sheets("Data").Range("AI2")
TxtTotalTests.Text = wbk.Sheets("Data").Range("AJ2")
wbk.Close False
TxtPassword.value = ""
'--------------- TEST CODE START ---------------
Dim i As Long
For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row
If Cells(i, 1).value = TxtPIN.value Then
Range(Cells(i, 1), Cells(i, 29)).Copy Destination:=targetSh.Range("A" & targetSh.Cells(Rows.Count, "A").End(xlUp).Row + 1)
End If
Next i
'--------------- TEST CODE END ---------------
UsrFrmAdminLogin.Hide
UsrFrmAdminDashboard.Show
Else
MsgBox "Either your account access has not been approved or you have entered an incorrect password!", vbOKOnly, "Returns - Admin Dashboard"
TxtPIN.value = ""
TxtPassword.value = ""
TxtPIN.SetFocus
Exit Sub
End If
Else
MsgBox "You are not authorised to use this system!", vbExclamation, "Returns - Admin Dashboard"
TxtPIN.value = ""
TxtPassword.value = ""
Exit Sub
End If
'--------------- TEST CODE END ---------------
End Sub
Thanks in advance.