Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2006
    Posts
    25

    Unanswered: Alt + F4 causes "Enter Parameter"

    I have a db that when forms are changed, one closes and the other opens.
    I use the onOpen and onClose to run a series of queries.

    I have an exit button that closes the screen and then quits the application.
    This method has no effect on the onOpen/onClose queries, but if somebody Alt + F4, my queries don't have a chance to run and requests me to "Enter Parameter" before it eventually debugs. Any clues? I need these queries to run in order to maintain a log of all users whereabouts.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    This is possibly because one of the queries has a reference to a form that is already closed at the moment the query runs.
    Have a nice day!

  3. #3
    Join Date
    Jun 2006
    Posts
    25
    My query that I run records the user which is located on the active form. How can I prevent it from debugging when Alt + F4 is keyed? Alt + F4 shuts down the database before it can run the OnClose query. Any suggestions?

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    The form will always execute the code present in the Form_Close event, whatever can be the method you use to close Access (except if you switch off the computer or something like that).

    Store the data that the query needs outside the form and run the query from the Form_Close event.

    1. The query (CloseUpQuery) was:
    Code:
    INSERT INTO Table2 ( ID, DS )
    SELECT Table1.Field1, Now() AS Expr1
        FROM Table1
        WHERE Table1.Field1 > Forms!Form1.Text1.Value
    It becomes:
    Code:
    INSERT INTO Table2 ( ID, ts )
    SELECT Table1.Field1, Now() AS Expr1
        FROM Table1
        WHERE Table1.Field1) > QueryData()
    2. In the Form_Close event use this code:
    Code:
    Private Sub Form_Close()
    
        QData = Me.Text1.Value
        CurrentDb.Execute "CloseUpQuery"
        
    End Sub
    3. In an independent module, place this code:
    Code:
    Option Compare Database
    Option Explicit
    
    Public QData As Variant
    
    Public Function QueryData()
    
        QueryData = QData
        
    End Function
    Now the query fetches its parameter from the QueryData() function and not from the reference to a form that can be closed at the moment it executes.
    Have a nice day!

  5. #5
    Join Date
    Jun 2006
    Posts
    25
    Great, got everything to work. Thanks Sinndho for your fast reply.

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

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