Dispaly modal form and showmessage error

Posted on 2007-10-02
Last Modified: 2010-04-05
I have two forms in an app, one which I will call the main form and a second form which is opened as a result of a button click that is called via the following piece of code


While the second form is displayed if I try to send an error via the showmessage routine, when the user clears the message the second form is closed also any idea how to bypass
Question by:elschott
    LVL 15

    Expert Comment

    Can you show us your code please.
    A showMessage call has nothing to do with forms, so you must be doing something else as well.
    LVL 13

    Expert Comment

    The answer might lie in the help file on Showmodal (See the "Note" below)

    Use ShowModal to show a form as a modal form. A modal form is one where the application can't continue to run until the form is closed. Thus, ShowModal does not return until the form closes. When the form closes, it returns the value of the ModalResult property.
    To close a modal form, set its ModalResult property to a nonzero value.
     If the form contains buttons with a ModalResult property set to a value other than mrNone, the form automatically closes when the user clicks one of those buttons and returns the ModalResult value as the return value of ShowModal.
    LVL 10

    Expert Comment

    Can you explain more.

    LVL 19

    Expert Comment

    can you please show some code like mikelittlewood requested?
    LVL 10

    Expert Comment

    i think below solution will work for you.
    But believe that this not good solution. You have to find the reason.

    ShowMessage('fgdfgdfg'); //your error message.

    Author Comment

    The call from form 1 to display the AddNewClassForm is from a button click as follows:


    The Add New Subject Form basically has 4 fields and two buttons a submit and a cancel. I want to check if the user presses the submit button that all fields have values entered, if not show an error and return to the form, if the form is completed correctly the database record is appended to the dataset and the user is returned ot the original form here is the submit code I hope it helps

      If (AddFaculty.Text = '') or (AddSubjectName.Text = '') then
          ShowMessage('All form fields are mandatory. Please complete form to add new subject');
          Maintennance_Form.SubjectID.Text := AddRecNum.Text;
          Maintennance_Form.Subject_Name.text := AddSubjectName.text;
          Maintennance_Form.Subject_AcaLvl.text := SelectYearCB.Text;

    I took out the and close lines and put another showmessage in there, which should show the message and then return to the form but when this show message is displayed it still closes the add new subject form, which made me think it had something to do with showmessage and showmodal


    LVL 13

    Accepted Solution

    Hi elschott

    As I mentioned earlier the answers might lie in the help file.
    Here " If the form contains buttons with a ModalResult property set to a value other than mrNone, the form automatically closes when the user clicks one of those buttons and returns the ModalResult value as the return value of ShowModal."

    In other words, check the "modalresult" property of the buttons on your "Add_New_Subject_Form". If they are set to ANYTHING other than "mrNone" they will close the Add_New_Subject_Form!
    LVL 10

    Expert Comment

    i agree with  rfwoolf.
    You are closing your form with 'CLOSE' function.
    So the model result of your Submit button must mrNone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now