Pat_The_Bat
Board Regular
- Joined
- Jul 12, 2018
- Messages
- 83
Working on this user login form and I've got it working except that every time I open the workbook, the userform appears on another screen. I want it to appear right in the middle of the excel application. I've researched this and I've come up with this piece of code, but it moves the userform over to the right position after the user already logged in. Any help is appreciated. I've been grinding away at this thing, and this is the last piece for me to be able to put this workbook in action!!!
This moves it over after the userform has already been filled out once and submitted. :/
Me.StartUpPosition = 0 Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * Me.Width)
Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * Me.Height)
This moves it over after the userform has already been filled out once and submitted. :/
Me.StartUpPosition = 0 Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * Me.Width)
Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * Me.Height)
Code:
Private Sub Workbook_Open()
MsgBox "Hello"
Login.Show
End Sub
'Then the code for Login is:
Public Sub Login_Click()
Dim Username, password As String
Me.StartUpPosition = 0
Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * Me.Width)
Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * Me.Height)
Application.ScreenUpdating = False
' Open Workbook A with specific location
Dim src As Workbook
Set src = Workbooks.Open("C:\Users\RPM User\Documents\LOCAL LAPTOP DOCUMENTS\authusers.xlsx", False, False, , password:="JaneyBear123!@#")
Dim ID1 As String
Dim ID2 As String
Dim ID3 As String
Dim PW1 As String
Dim PW2 As String
Dim PW3 As String
Dim valueBookB As String
ID1 = src.Worksheets("sheet1").Range("A2")
ID2 = src.Worksheets("sheet1").Range("A3")
ID3 = src.Worksheets("Sheet1").Range("A4")
ID4 = src.Worksheets("Sheet1").Range("A5")
PW1 = src.Worksheets("Sheet1").Range("B2")
PW2 = src.Worksheets("Sheet1").Range("B3")
PW3 = src.Worksheets("Sheet1").Range("B4")
PW4 = src.Worksheets("Sheet1").Range("B5")
Debug.Print ID1
Debug.Print PW1
Username = TextBox1
password = TextBox2
Debug.Print Username
Debug.Print password
src.Close FalseD
If Username = ID1 And password = PW1 Then
MsgBox "Thank You For Succesfully Loggin In!", vbInformation
Unload Me 'unload this form
Else
MsgBox "Invalid Credentials", vbCritical
Debug.Print
'now Close the workbook
ActiveWorkbook.Close
End If
Application.ScreenUpdating = True
Worksheets("Summary").Activate
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = VbQueryClose.vbFormControlMenu Then
MsgBox "Cannot close the userform !!"
Cancel = True
End If
End Sub