Results 1 to 7 of 7

Thread: Form_QueryUnload

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    296

    Form_QueryUnload

    I wonder When else statement Execute which is vbNo the form will disappear and cmdsave does not setfocus. Can anyone tell me why?

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode
    2. As Integer)
    3.  
    4. If Response = vbYes Then
    5. FormMain.Show
    6. Else
    7. cmdSave.SetFocus
    8. End If
    9.  
    10. End Sub

  2. #2
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    I'm not sure where u got ur Response result... I take it that u are using a msgbox somewhere. Anyway, if u dont want the form to close u need to set Cancel to True (or a non zero number). If frmMain is the current form then u dont need to show that at all.
    VB Code:
    1. If Response = VbNo then
    2.     Cancel = True
    3.     cmdSave.Setfocus
    4. End if
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  3. #3
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    put:
    Cancel = 1
    before the SetFocus

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Execute English language...

    Errrr...Don't know exactally what you're getting at...
    What do you want it to do when the response is vbNo?

    Is it that:

    I am assuming:

    Code:
       Response = MsgBox("Save Changes?", vbYesNo,"Save")
    When you select NO from the message box you want the form to stay loaded and the save button to gain focus? Is this correct? If so then where you have the ELSE statement you need:

    Code:
    ELSE
        Cancel = True
        cmdSave.SetFocus
    END IF
    Think that's right...

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    296
    Thanks people for helping althought my code was confuse but everyone

    I solved with all the comments posted. Thank you so much

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    296
    By the way, i have just posted a question on ODBC setup. I hope everyone can help again

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    If you close the form down and it checks to see if work needs to be saved it's usually common practice to have a Cancel option to. The code will look like:

    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode 
    As Integer)
       Response = MsgBox("Save Changes?",vbYesNoCancel + vbQuestion,"Save")
       Select Case Response
          Case vbYes
              If Not Save_Changes Then
                  Cancel = True
              End If
          Case vbNo
              'No Code Here!!!
          Case vbCancel
              Cancel = True
       End Select
       If Cancel Then
           cmdSave.SetFocus
       End If
    End Sub
    
    Private Function Save_Changes() as Boolean
       'Code for saving data
    End Function
    If you click NO then the form just unloads and doesn't Save. If you Click cancel then the form stays and it doesn't save.
    If you click Yes and the Save function Returns a value of False then it hasn't save correctly and the form stays open so you can sort the changes out...

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