Userform always opens on other monitor (dual monitor)

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)


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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)


I just reviewed that thread. That doesn't solve my problem. For some reason, my userform appears, and then it requires me to put text into it before it steps through the code. Once I put the text in, THEN it adheres to those lines of code and moves to that location in the center of the application.

I thought that the ME codes told the object how to behave??? I don't understand why the form appears and then follows that instruction after that fact!!!!?????

I'm truly stumped.
 
Upvote 0
Try removing Application.ScreenUpdating = False and see if ithat makes a difference.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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