I was not able to use your file because it opened with Excel on-line and no VBA or Userforms. If uploading workbooks, zip the file first and then we can download the Zipped file and un-zip. However, the following is the code to position a second Userform on an already open Userform.
Your Screen Shot displays 2 x Userform1. Not sure how you did that, but the code below has Userform1 as the first Userform to display and then Userform2 is positioned over top of Userform1.
Rather than run the code from buttons on Userform1, the code is run when the User clicks in TextBox1 or TextBox2. You should be able to assign it to buttons if desired. The cursor is positioned in TextBox3 when the Userform1 is shown.
Feel free to get back to me if any problems arise and I will attempt to assist further.
The following code to show Userform1 can be wherever you want but I have placed it in Module1 and called it with a Form Control Button positioned on a worksheet.
Sub Button1_Click()
'Called from a Form Control Button on Sheet1
UserForm1.Show
End Sub
The following code goes in Userform1 module. I have used 3 controls on Userform1, TextBox1, TextBox2 and TextBox3. Note all of the comments.
Private Sub UserForm_Initialize() 'Event Sub. (Do not rename sub)
Me.TextBox3.SetFocus 'Position cursor in field other than TextBox1 or TextBox2
End Sub
Private Sub TextBox1_Enter() 'Event Sub. (Do not rename sub)
'This code runs as an Event when the User Clicks in TextBox1 on Userform1
Dim FormBorderSize As Double
Dim FormTitleSize As Double
Dim dblTop As Double
Dim dblLeft As Double
With Me 'Me is generic reference for the Userform (In this case Userform1)
'Get co-ordinates to display Userform2 under TextBox1 on Userform1
FormBorderSize = (.Width - .InsideWidth)
FormTitleSize = .Height - (.InsideHeight + FormBorderSize)
dblTop = .Top + .TextBox1.Top + .Height - .InsideHeight + FormTitleSize
dblLeft = .Left + .TextBox1.Left + .Width - .InsideWidth - FormBorderSize
End With
'Position of Userform2 under TextBox1
With UserForm2
.StartUpPosition = 0
.Top = dblTop
.Left = dblLeft
End With
UserForm2.Show
End Sub
Private Sub TextBox2_Enter() 'Event Sub. (Do not rename sub)
'This code runs as an Event when the User Clicks in TextBox2 on Userform1
Dim FormBorderSize As Single
Dim FormTitleSize As Single
Dim dblTop As Double
Dim dblLeft As Double
With Me 'Me is generic reference for the Userform (In this case Userform1)
'Get co-ordinates to display Userform2 under TextBox2 on Userform1
FormBorderSize = (.Width - .InsideWidth)
FormTitleSize = .Height - (.InsideHeight + FormBorderSize)
dblTop = .Top + .TextBox2.Top + .Height - .InsideHeight + FormTitleSize
dblLeft = .Left + .TextBox2.Left + .Width - .InsideWidth - FormBorderSize
End With
'Position of Userform2 under TextBox2
With UserForm2
.StartUpPosition = 0
.Top = dblTop
.Left = dblLeft
End With
UserForm2.Show
End Sub
The following code all goes in Userform2 module. It prevents the User from moving Userform2.
Dim dblFixedTop As Double 'At top of Userform2 Module
Dim dblFixedLeft As Double 'At top of Userform2 Module
Private Sub UserForm_Activate() 'Event Sub. (Do not rename sub)
'Assign the values for Userform Top and Left to variables
dblFixedTop = Me.Top
dblFixedLeft = Me.Left
End Sub
Private Sub UserForm_Layout() 'Event Sub. (Do not rename sub)
'Prevents user from moving the Userform
'dblFixedTop and dblFixedLeft are declared at top of module
'and values are assigned in UserForm_Activate event
Static bolFormActive As Boolean
'Executes only when form is activated and position is known
If bolFormActive Then
If Me.Top <> dblFixedTop Then
Me.Top = dblFixedTop
End If
If Me.Left <> dblFixedLeft Then
Me.Left = dblFixedLeft
End If
End If
bolFormActive = True
End Sub