Here's my code.

Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Set db = Nothing
    Set fso = Nothing
    Set rs = Nothing
    Set Win32Script = Nothing
    Set WkSpc = Nothing
    wskConnectionHandler.SendData CLIENT_MESSAGE_DISCONNECTED
    wskConnectionHandler.Close
    Unload Me
End Sub
This is supposed to send a disconnect packet when the user clicks the close button. However, I get an error "Invalid operation at current state." Debugging revealed that this is because the Winsock control begins to close the connection immediately after the user clicks the X, and this is bad because the server will never know that the client has disconnected when they click the X. How can I prevent this from happening?