The form has no business knowing about Application.Visible state. As this answer shows, Button2 set it to False, it's Button2's job to set it back to True.
Your code works perfectly fine here - the problem is likely in code you haven't posted. Keep procedures' responsibilities well defined and you won't have these issues.
Another common trap you've fallen into (as did the other answer), is to work with a stateful default instance. Forms are objects - treat them as such!
Application.Visible = False With New frmDataCol1 .Show ' here you still have access to the form's state! End With Application.Visible = True
Now, if you don't handle QueryClose, that red "X" button effectively destroys the object and, normally, you absolutely don't want that.
What you want, is to control the object's lifetime yourself - that's what you have that With block for!
So you do handle QueryClose, but only to say "Hide the form instance, don't destroy it!" - like this:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = vbFormControlMenu Then Cancel = True Me.Hide End If End Sub
That way when your dialog gets closed, the calling code can still access the public state and act accordingly. If you worked off the default instance, letting QueryClose destroy the instance causes the state to be lost. And since it's a default instance, a brand new one gets created as soon as you query that state, making the bug extremely difficult to find... if you don't know how objects with a default instance work.
If CloseMode = vbFormControlMenu Then Debug.Print "Flag01" Application.Visible = TrueAdd a debug print statement to make sure you are executing the statement inside the if conditionButton2_Clickto doWith New frmDataCol1and.Showinstead, and change yourQueryCloseimplementation toHidethe form instance given avbFormControlMenuclose mode; that way you'll take control of the object's lifetime ("X" button destroys the object by default). Also, follow jkpieterse's advice.