Results 1 to 5 of 5

Thread: Why is my old form poping back up?

  1. #1

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526
    I'm trying to get from the main form to the final form of my program which gives the user results from their quiz. The problem I'm having is that it loads the Summary but then it goes back to the code from the Quiz. Here's my code to get me from the Quiz form to the Summary form:

    frmSummary.Show
    frmSummary.Top = frmQuiz.Top
    frmSummary.Left = frmQuiz.Left
    Unload frmQuiz

    The Summary code is very simple:

    Private Sub Form_Load()
    lblTally.Caption = " " & Correct & " out of " & (QAsked + 1) & Chr$(13) & " Your Score:" & Int((Correct / (QAsked + 1)) * 100) & "%"
    End Sub

    Private Sub cmdSubmit_Click()
    End
    End Sub

    But instead of waiting for the Submit Click (which has been titled "Exit Program", it goes right back into the Quiz form code. Can anyone tell me what the heck is going on?


    mikeycorn

  2. #2

  3. #3
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305

    um

    did u by mistake put "frmquiz.show" in the unload event of frmsummary?

  4. #4
    Guest
    try this..
    it should work...
    Code:
    Private Sub cmdSubmit_Click() 
    Dim F As Form
    For Each F In Forms
    Unload F
    Next F
    End Sub

  5. #5
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    All good solutions

    But in case you were looking for a much simpler answer
    From the example, it appears you are be calling the code form within a Sub on the frmQuiz (or other) form. Also, I presume there is code following the "Unload frmQuiz" statement?

    In this case,

    'frmQuiz is already running and user hits a button to get to summary form

    frmSummary.Show
    ' here, the frmSummary is created and displayed
    ' I would use load frmSummary, then set the top and left, then frmSummary.show. Looks nicer

    frmSummary.Top = frmQuiz.Top
    frmSummary.Left = frmQuiz.Left
    ' frmSummary's position is adjusted

    Unload frmQuiz
    ' Attempt to unload frmQuiz should work

    If you put a trace message in frmQuiz_Unload, you will see that the Unload frmQuiz works.

    NExt, as I presumed there to be another statement, the frm summary is still loaded, but perhaps now in the background, and the calling form (perhaps frmQuiz, or some code that eventually references a frmQuiz) causes a new frmQuiz to be created.

    Short answer in solving your immediate problem is to use Hide instead of unload, OR on the frmSummary.Show line, use frmSummary.Show vbModal,Me which will force the system to wait for the frmSummary form to close before running the calling Sub's next statment.

    Hence the reason I would Load the frmSummary, then change the top, left attributes, THEN I would either unload or hide the frmQuiz, and finally show the frmSummary.

    Code:
     
    ' in a nutshell
    Load frmSummary
    frmSummary.Top = frmQuiz.Top 
    frmSummary.Left = frmQuiz.Left   
    frmQuiz.Hide
    frmSummary.Show frmSummary, vbModal, Me
    I hope this helps in additoon to the previous replies

    Paul Lewis

Posting Permissions

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



Click Here to Expand Forum to Full Width