Results 1 to 4 of 4
  1. #1
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328

    Delete query using vba

    I am using both A2003 and A2007.


    I am using the statement below as a delete query..

    DoCmd.RunSQL "Delete myTable.* from SomeTable where idquote=" & qq & ""

    However, I have several tables that I would like to clear depending on other conditions so would like to run the sql statement with the table name as a variable.. I have tried:

    Dim Mt as string
    MT="SomeTable"

    Then inserting MT in place MyTable in the SQL statement. Doesn't work. Do I need some combo of quote, ampersands and apostrophies?

    Another problem is with the Where function. Works ok, for number, but can't figure out how to do same thing when qq is a string.

    Any help much appreciated

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It would have helped if you'd posted your failing effort, but:

    "DELETE * FROM " & MT & " WHERE..."
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    Thanks very very much-works fine, much appreciated. I did something similar with 2nd part of question and works! Thanks again. "Wino" Moderator ???

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!

    I'm a moderator, and many would say a wino, thus "wino moderator".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 01-24-2012, 02:16 PM
  2. Trying to Delete record using delete query
    By MooseOTL in forum Access
    Replies: 13
    Last Post: 10-04-2011, 02:30 AM
  3. Delete Query
    By Cheshire101 in forum Queries
    Replies: 3
    Last Post: 06-29-2011, 08:35 AM
  4. Replies: 11
    Last Post: 03-30-2011, 01:08 PM
  5. HELP with Delete Query
    By brown in forum Queries
    Replies: 1
    Last Post: 04-22-2009, 10:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums