Hello Forum and thanks in advance for any guidance.
I have a very basic userform with 5 textboxes, 2 datepickers (those in a frame) and a command button to send the entries to a worksheet. The userform is launched by a button on the Excel 2010 worksheet. I also have found code that adds a minimize button (with maximize disabled) next to the X close button in the title bar which works great and what I'm looking for.
However, it seem that the minimize button code somehow blocks or stops the focus from being set in the first textbox. I've tested this by removing this minimize button code from the userform code and seeing that the focus works just fine without it, landing in the first textbox where the tab index is 0 and tab stop is true. I've tried to add SetFocus code to the userform, in the macro for the launch button, within the minimize button code, etc., but to no avail. If I had more hair, i'd be pulling it out right now! 
I want to keep the minimize button code and make that functionality available to the user as I have ShowModal set to false in case the user wants to link to help/reference resources from the worksheet to help them complete any of my forms, as the workbook is a tool to build a communications plan.
Is there a way to modify the following code to stop it from blocking the focus being set to the first textbox? Additional code I can add to make it happen?
Again, any help is much appreciated!
The UserForm Code:
'**********************************************
'Provides Minimize/Maximize button, disables Maximize button in taskbar
Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLongA Lib "user32" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Sub UserForm_Activate()
Dim hWnd As Long, exLong As Long
hWnd = FindWindowA(vbNullString, Me.Caption)
exLong = GetWindowLongA(hWnd, -16)
If (exLong And &H20000) = 0 Then
SetWindowLongA hWnd, -16, exLong Or &H20000
Me.Hide: Me.Show
End If
Me.txtCommPlanName.SetFocus '<<<One of my weak attempts at getting focus in the first textbox!
End Sub
'**********************************************
'**********************************************
'Sends userform control values to specified worksheet cells and closes form
Private Sub btnUpdatePlan1_Click()
Worksheets("SituationAnalysis").Range("E11").Value = Me.txtCommPlanName '<<<NOTE: This is the first textbox
Worksheets("SituationAnalysis").Range("H12").Value = Me.txtBusSponsor
Worksheets("SituationAnalysis").Range("H13").Value = Me.txtCommLead
Worksheets("SituationAnalysis").Range("L12").Value = Me.txtCommPlanOwner
Worksheets("SituationAnalysis").Range("L13").Value = Me.txtContentApprover
Worksheets("SituationAnalysis").Range("T12").Value = Me.dtpkrCommPlanStart
Worksheets("SituationAnalysis").Range("T13").Value = Me.dtpkrCommPlanEnd
End Sub
'YellowRefresh: Empties form, keeps it open (technically, closes and reopens), no changes sent to worksheet
Private Sub btnClearForm_Click()
Unload Me
frm1BasicCommPlan.Show
End Sub
My Launch Button Macro Code:
'Basic Communication Plan button
Private Sub BasicCommPlanButton_Click()
frm1BasicCommPlan.Show
End Sub
Bookmarks