Runtime Error 400: “Form already displayed; can't show modally,” explained and fixed

Error 400, “Form already displayed; can't show modally”, fires when code tries to display a form as modal (Show vbModal) while that same form is already on screen as a modeless window. A form's modality is fixed while it is displayed: it cannot be promoted from modeless to modal in place. The statement is reasonable and the form exists; the sequence is what is wrong. Either show it modally from the start, or hide/unload the modeless instance first. It is a window-management bug in the code.

For people who just run the program

  1. Expect it where a window can be opened two ways. A panel that opens as a floating tool window, and also as a pick-one dialog from another screen, is the standard setup: open it the first way, then trigger the second.
  2. Close the already-open window and retry. If the action then works, the sequence explanation is confirmed, and that is worth telling the maintainer in those words.
  3. Note which window was already open. The name of the window you had open is the missing half of the bug report.
  4. Do not force-close the whole program unless it wedges. A normal close of the duplicate window is enough; the error itself changes nothing.

For people who write the code

  1. Test visibility and modality before Show. If the form is visible, either use it as it is, or hide it and then show modally:
  2. If frmPicker.Visible Then frmPicker.Hide
    frmPicker.Show vbModal   ' legal once it is no longer displayed
    ' Calling Show vbModal while Visible was error 400.
  3. Choose modality per form, not per call site. Designs where the same form is sometimes modal and sometimes not generate this whole family (400, 401, 402). If both styles are truly needed, two forms or an explicit state machine beat ad hoc switching.
  4. Remember the default instance trap. Referring to a form by name uses its default instance; a second “copy” shown modally is that same instance. Code expecting separate instances must create them with New and manage each explicitly.
Hide is not Unload, and the difference matters here. Hiding the modeless form makes the modal Show legal while keeping its state; unloading also works but discards the state. Programs that unload out of habit and then wonder where the user's half-finished work went are making the second mistake while fixing the first.

If it still happens

If the form is not visibly on screen yet error 400 insists it is displayed, it may be displayed off-screen or with Visible state left over from the default instance being referenced earlier in the session (any reference to its controls loads it). Check the Forms collection for the live instance and its Visible property rather than trusting what is on the monitor.

Common questions

What does modal actually mean? A modal form demands attention: while it is shown, the user cannot interact with other windows of the program until it closes. A modeless form floats alongside the rest. Modality is chosen when the form is shown and cannot change while it is displayed.

Can two different forms hit error 400 together? No. The error concerns one form being asked to show modally while it is already displayed. Two different forms, one modal over a modeless other, is the normal, legal arrangement.

Related errors

Runtime Error 401 · Runtime Error 402 · Runtime Error 361