Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Access (https://www.askmehelpdesk.com/forumdisplay.php?f=441)
-   -   Delete Query (https://www.askmehelpdesk.com/showthread.php?t=459198)

  • Mar 21, 2010, 12:07 AM
    znet2705zc
    Delete Query
    Hi ,
    In My project (Access 2007) , I Used a "Delete Query" To Delete A Record.
    When The Query Is Runnig ,It Ask About Deleting A Record.
    Can We Umit That Message?(In Other Hand , It Delete A Record Without Asking)

    Thanks.
  • Mar 21, 2010, 02:24 AM
    ScottGem

    How are you triggering the query?
  • Mar 21, 2010, 11:37 AM
    znet2705zc

    What do you mean?
  • Mar 21, 2010, 11:51 AM
    ScottGem

    A Delete query is an Access object that removes records from a table. To run a Delete query, you have to trigger it in some way. You could simply double click the query name in the Navigation Pane or you can call the query from a macro or on a button on a form.

    If you are just running it from the Nav Pane, then there is no way to turn off the Warnings. If, you run it from a macro or from a VBA module, there are ways to turn off the warnings. That's why I asked how you trigger it so I can know what the best way to tell you how to do it is.

    It would also help to know what record you are deleting or to see the SQL for the query. You would have to be providing some criteria for the query so you don't delete all the records in the table.
  • Mar 21, 2010, 12:27 PM
    znet2705zc

    I click a button that it run a macro.
    And criteria is : [Forms]![main_form]![Txt_del]
  • Mar 21, 2010, 02:39 PM
    ScottGem

    Ok, In the macro add a line before you execute the query:

    SetWarnings False

    After the query add a line:

    SetWarnings True
  • Mar 21, 2010, 11:22 PM
    znet2705zc

    I Tried , But I couldn't.
    The Macro is Like The Follow , Can you Explain More ?

    Macro Name :
    Condition :
    Action : OpenQuery
    Argument :Q_Del,DataSheet,ReadOnly
  • Mar 22, 2010, 03:59 AM
    ScottGem

    I generally do not use macros they are too limiting. But in a macro each action is a line. What you show above is is the OpenQuery line. You need to ADD lines above and below that line to turn SetWarnings on and off.

    The VBA code would be:

    SetWarnings False
    DoCmd.OpenQuery "Q_Del"
    SetWarnings True

    You don't need the other parameters for the OpenQuery method as they are the defaults.
  • Mar 22, 2010, 08:21 AM
    znet2705zc

    I Added That Two Line , And The Result was This Error :

    Compile Error: Sub Or Function Not Defined.
  • Mar 22, 2010, 09:25 AM
    ScottGem

    You added them to the macro? Did you pick SetWarnings from the list of Actions?
  • Mar 23, 2010, 12:55 PM
    znet2705zc

    No, I didn't.
    Now I do that , and finally it solve.

    Thanks a lot.
  • Mar 23, 2010, 01:36 PM
    ScottGem

    You're welcome

  • All times are GMT -7. The time now is 09:19 AM.