Word VBA - easily remove form frame?

249 Views Asked by At

I'm trying to create a user entry form which both captures the users input and displays a status update message. The slickest way I think of doing it is to have my modal form for the user entry display over a modeless form. After the user enters their info and clicks OK, the info from the modal form is copied to the modeless form, the modal form is closed and status updates get pushed to the modless form as things change during processing: Modal form over a modeless form

Hopefully, with a lot of messing about with positions, it will look relatively seamless. My challenge is getting rid of the frame on my modal form. I've done a lot of searching and it seems to involve completely redrawing the form from base libraries - is there seriously no easier way to do it?

1

There are 1 best solutions below

1
On

I would not use a 2nd form but just place a simple Frame on top of your form. When you want to show the "modal form", just set the visibility of the frame to True, and when you want to hide it, set it to False - all controls (in your case, the input field and the OK and Cancel button) that are placed on the frame are automatically shown or hidden.

If you have controls outside the "modal form" frame that you don't want to be active at that time, set them to enabled = False. You could handle this with a simple routine within your form.

In this example I have a frame FrameModal painted on top of the form. Note that this frame could be places over other controls.

Option Explicit

Private Sub UserForm_Activate()
    showHideModalFrame False
End Sub

Private Sub buttonShowModal_Click()
    ' Show the "modal" dialog
    showHideModalFrame True
End Sub

Private Sub buttonOK_Click()
    ' Do your stuff here...
    Me.tbUpdates = Me.tbUpdates & vbCrLf & Me.tbInput
    ' Hide the "modal" dialog"
    showHideModalFrame False
End Sub

Private Sub showHideModalFrame(show As Boolean)
    Me.FrameModal.Visible = show
    Me.buttonShowModal.Enabled = Not show
End Sub

enter image description here

Start the form

enter image description here

Click the show button:

enter image description here