PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Problem in switching between Forms-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] Problem in switching between Forms

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    49

    Resolved [RESOLVED] Problem in switching between Forms

    Hi everyone,

    Could someone help me with my problem. I'm prompted with this Run-time error '400', which says that "Form already displayed; can't show modally" when for example I have a button (cmdMisc) in Form1 and once this button is clicked, it shows Form2. In Form2, I also have a button (cmdMain) that is clicked whenever I want to go back to Form1. I'm trying to work around this problem using vbModal, vbModeless, Hide, Unload and Load but the same error occurs.

    Here's the code I made:

    Form1

    Private Sub cmdMisc_Click()

    Form2.Show

    End Sub

    Form2

    Private Sub cmdMain_Click()

    Form1.Show

    End Sub

    Thank you so much for your help.

    Cheers,
    Radic

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,660

    Re: Problem in switching between Forms

    is this in VB6 or an office application?
    i tried this in vb6 no problem works fine
    office userforms are a bit different, as they are modal by default,
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    49

    Re: Problem in switching between Forms

    Oh I'm sorry. It's an office application, particulary VBA in excel. How can I then resolve this problem in this kind of environment? Thanks once again!

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,660

    Re: Problem in switching between Forms

    i tested in excel, works fine,
    in userforms 1 and 2
    vb Code:
    1. Private Sub UserForm_Click()
    2. UserForm1.Show 0 'vbmodeless
    3. End Sub
    note you must also make the first call to open the first form modeless, otherwise, assuming userform1 is opened first, if it is not opened modeless, you will get an error when you try to show it from userform2
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    49

    Re: Problem in switching between Forms

    It worked perfectly!!! Thanks so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width