Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query_unload not firing

Status
Not open for further replies.

sochidog

Technical User
Jun 26, 2003
22
CA
I've put simple msgboxes in the code and it doesnt fire, whereas the unload works fine. whats going on?
 
Hi!
Nothing out of the norm. I havent even got to the part where I stop the unload - Im still not seeing the QueryUnload fire at all! I do get msgboxes when I use the unload - and stopping it there is tough.


Private Sub Form_QueryUnload(Cancel As Integer, unloadmode As Integer)

Select Case unloadmode
Case vbFormControlMenu
MsgBox ("close button pushed:" & unloadmode)
'Cancel = 0
Case Else
MsgBox ("Properlogout:" & unloadmode)
'Cancel = 1
End Select

End Sub
 
try

Select Case unloadmode
Case vbFormControlMenu
MsgBox ("close button pushed:" & unloadmode)
Cancel = False
Case Else
MsgBox ("Properlogout:" & unloadmode)
Cancel = True
End Select

End Sub

 
I've commented the true/false 0/1 part out... I'd be happy even seeing a messagebox, which i am not.
 
what version of access are you running? I just tested the code in XP and it worked fine..

 
Private Sub Form_Unload(Cancel As Integer)

Select Case unloadmode
Case vbFormControlMenu
MsgBox ("close button pushed:" & unloadmode)
Cancel = False
Case Else
MsgBox ("Properlogout:" & unloadmode)
Cancel = True
End Select

End Sub

paste this entire code into a form and test it..

 
here is if you want to "Activate" the Cancel = True or False


Dim Resp As Integer

Resp = MsgBox("close button pushed:" & unloadmode, vbYesNo, "Help")

If Resp = vbYes Then
Cancel = False
Else
Cancel = True
End If


 
This form is the logout form, replacing a vbYesNo popup. If they hit logout, it gracefully closes down, or else re- opens the main menu. I am capturing the "X" close, so it says "use the logout button". So basically what's happening now is that no matter if i click logout or X, it always says the X button pushed. Putting the cancel to true, stops the unload though.

Private Sub Form_Unload(Cancel As Integer)

Select Case unloadmode
Case vbFormControlMenu
MsgBox ("X button pushed:" & unloadmode)
Cancel = True
Case Else
MsgBox ("Proper logout button:" & unloadmode)
Cancel = False
End Select

End Sub

Private Sub QuitButton_Click()

Call Form_Unload(1)

End Sub
 
you need VbYesNo..how else are you telling the DB what the user pressed? then you must tell the DB what the user pressed..thats why I posted the code with Resp = Whatever.

 
I was trying to get away from pop ups... I have decided to scrap a whole bunch of code and move in another direction. Hopefully I will use your code in another endeavour. Thanks for your advice!
 
Hi sochidog,

Don't give up so easily! Try adapting your method using a variable.

In the Declarations section of your Form:

Dim booCanClose As Boolean

In the On Load or On Open event:

booCanClose = False

In the On Click event of your Close button:

booCanClose = True
DoCmd.Close acForm, Me.Name

In the Form's UnLoad event:

If booCanClose = False Then
MsgBox "Improper logout method:"
Cancel = True
Else
MsgBox "Proper logout method:"
Cancel = False
End If

Obviously, edit the above to suit your own needs.

Bill
 
Hi sochidog,

How did you get on with this?

Someone else has just asked a similar question in the Forum.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top