Bonnie Z
Bonnie Z

Reputation: 55

Excel userform with scrollbar won't open at top of form

I am trying to get my userform to open at the top of the form but no matter what I have tried it keeps opening at the bottom of the form instead. I have included below my code for the UserForm_Initialize() as well as a picture of how the form opens.

Private Sub UserForm_Initialize()

Dim myPath As Variant

Application.ScreenUpdating = False
Application.DisplayAlerts = False

'ActiveWorkbook.ChangeFileAccess Mode:=xlReadOnly
Workbooks("ECP Logistics Tool.xlsm").Activate

'I have tried several methods based on my Google attempts to fix this issue:
'Hiring_Validation_Form.ScrollTop = 0
'Hiring_Validation_Form.Scroll (fmScrollActionBegin)
'Neither of these work, the form still opens at the bottom instead of the top.

myPath = ThisWorkbook.Path

Image1.Picture = LoadPicture(myPath & "\Resources\ECP Logo.jpg")

'Set default date for Start Date
Date1 = Workbooks("ECP Logistics Tool.xlsm").Sheets("Lists").Range("M2").Value

Hiring_Validation_Form.DTPicker1.Value = Date1

'Set default date for End Date
    'Change start date to 1st monday after today's date
    Workbooks("ECP Logistics Tool.xlsm").Activate
    Sheets("Lists").Select
    Range("N2").Select
    ActiveCell.FormulaR1C1 = "=TODAY() + 70"
    CurDate = Cells(2, 14).Value
    For i = 1 To 7
        If Weekday(CurDate) <> vbMonday Then
            CurDate = CurDate + 1
        Else
            Range("N2").Select
            ActiveCell.FormulaR1C1 = CurDate
            GoTo exitLoop
        End If
    Next i

exitLoop:

    Date2 = Workbooks("ECP Logistics Tool.xlsm").Sheets("Lists").Range("N2").Value

    Hiring_Validation_Form.DTPicker2.Value = Date2

End Sub

enter image description here

Upvotes: 0

Views: 1596

Answers (1)

klausnrooster
klausnrooster

Reputation: 560

Userform showing Tab Stop @Bonnie Z, In the form design right-click on the combobox or listbox with the label, "Select the Training Type:" Choose (click) "Properties". Set the TabIndex to 0. Save and test the effect on the loading behavour. If it works the way you want, go back and set the others (...boxes and buttons, not the labels) from top to bottom (of the form) to 1, 2, 3, ... and so on. From what we can see, the "Submit" button would have TabIndex 16. But it depends what the actual first box is on your form. Not sure we see it in the paste. See my paste belo.., er, above.

Upvotes: 2

Related Questions