Hello all!
I am experiencing some odd behavior with a UserForm, the user must click on a button twice to trigger the onClick event.
This odd behavior only occurs when I call the procedure to show the form through a custom menu. When I execute the procedure from the VBA window, the form behaves properly.
The UserForm is a very basic About box to display version and notes. It has a command button for closing it with the following:
Private Sub btnClose_Click()
Me.Hide
End Sub
The procedure to show the forms:
Public Sub interactionShowForm(strFormName As String, Optional enmModal As FormShowConstants = vbModal)
Dim obj As Object
On Error GoTo HANDLER_ERROR
'If form is already loaded, bring it up
For Each obj In VBA.UserForms
If (StrComp(obj.Name, strFormName, vbTextCompare) = 0) Then
obj.Show enmModal
GoTo HANDLER_FOUND
End If
Next obj
'Form not loaded already, do it now
Set obj = VBA.UserForms.Add(strFormName)
obj.Show enmModal
HANDLER_FOUND:
With obj
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
End With
GoTo HANDLER_EXIT
HANDLER_EXIT:
Set obj = Nothing
Exit Sub
HANDLER_ERROR:
errorSummarize Err, "modInteraction.interactionShowForm"
End Sub
Using the procedure below gets proper response from the command button.
Public Function testForm1()
interactionShowForm "frmAbout"
End Function
Using the procedure below emulates the call from a menu. This causes the odd behavior of clicking twice to get the event to trigger.
Public Function testForm2()
Application.Run ThisWorkbook.Name & "!interactionShowForm(""frmAbout"")"
End Function
In summary: What gives?
Bookmarks