Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to Emulate a Modal Form in VB

Posted on 2002-07-03
4
Medium Priority
?
335 Views
Last Modified: 2012-05-04
Showing Drop-Down Forms from Modal Forms.

One problem with this technique is that you cannot use it directly from a form shown with modally in VB, otherwise you get the error message "Can't show non-modal form when modal form is displayed". There 'must' be a workaround for this problem by which you can emulate showing the form modally.
 
Can anybody help me out with this problem ?
Thanks
0
Comment
Question by:Temujin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
fnizet earned 400 total points
ID: 7127233
You can disable the calling form.
Let's say MainForm calls ModalForm (which is not modal at all), you'll do
ModalForm.Show
MainForm.enabled = false

Then in ModalForm, you can do to call your DropDownForm :
DropDownForm.Show
ModalForm.enabled = false

When you close your "modal-est" form, you just enable the calling form. Let's say you have a button to close the DropDownForm :
Sub CloseDropDown_Click()
    Me.Hide
    ModalForm.enabled = true
End Sub

0
 
LVL 2

Expert Comment

by:fnizet
ID: 7127292
To work properly, you may need to define 2 functions, one to call a modal form, the other to return from a modal form. You need to manage an array of the forms you locked, because several forms may need to be locked :

Dim lockedForms(1, 3)

Sub callModal ( calledForm as Form, caller as Form)
for each f in Forms
  if (f.hwnd<>calledForm.hwnd) ' prevent from self locking in case called form is already loaded
     And (f.enabled) then
    f.enabled = false
    i = Ubound(lockedForms(1))
    Redim Preserve lockedForms(i+1, 3)
    lockedForms(i, 1) = calledForm.hwnd 'save ID of calledForm, prevents unlocking of previously lock forms
    lockedForms(i, 2) = f.hwnd 'save ID of locked form
    lockedForms(i, 3) = caller.hwnd ' just to know which form to unlock
  end if
next
calledForm.Show

End Sub

Sub unlockForms(modalForm as Form)
  Dim formToShow As Form
  n = Ubound(lockedForms(1))
  do while (n>0 and lockedForms(n, 1) = modalForm.hwnd)
    for each f in Forms
      if f.hwnd = lockedForms(n, 3) then Set formToShow = f
      if f.hwnd = lockedForms(n, 2) then
        f.enabled = true
        exit for
      end if
    next
    n = n - 1
  loop

  Redim Preserve lockedForms(n+1, 3)
  modalForm.hide
  formToSHow.Show
End Sub

I have not tested this code, but the idea is here.
0
 

Author Comment

by:Temujin
ID: 7130446
your first method worked fine in my project.

Thank you very much mr fnizet.
0
 
LVL 2

Expert Comment

by:fnizet
ID: 7131273
you're welcome and thanks for the A grade.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question