Results 1 to 8 of 8
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    670

    auto running a delete query onclose() event

    i want to run a delete query on my forms close event procedure. i have the following code:
    (code)


    dim db as database
    set db ~ currentdb
    docmd.set warnings false
    db.execute "queryname", dbfailonerror
    setdb ~ nothing
    docmd.setwarnings true
    (/code)

    this debugs with no problems, but when i close the database it doesnt delete the blank entries? i have also tried the same code on my formload() event and had the same results?

  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,518
    What's the SQL of the query? I'm not familiar with the tilde being a valid substitute for the equals sign. You don't need the SetWarnings lines; the Execute method doesn't throw the warnings.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    670
    Oh it is an equal sign, sorry hit the wrong key! The SQL for the query is:

    Code:
    DELETE tbl_jp.date
    FROM tbl_jp
    WHERE (((tbl_jp.date) Is Null));

  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,518
    It's always best to copy/paste code here, so we can see exactly what you've got. That SQL looks okay (I would have DELETE *...). You're saying there are records remaining where the date field is Null? Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    670
    there are date fields null because when the record is modified/updated if the prsn updating hits the plus sign instead of the save record it creates a blank entry. unfortunately i am unabble to post a sample of the db. and I am sure that is a hindrance in assisting. any otther thoughts, on why this isn't working or a different way to make it work?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Are you sure the code is running? Add a message box or something to test if you're not sure.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    670
    I had numerous onclose() event codes running, so I moved this code to be the 1st code run, directly after the onclose() and it is working now. Now I am curious, does it matter what order you have your event's in?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Generally speaking I would have expected that to work at any point in the process, but I suppose it depends on what else was being done.
    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. Query with a running sum
    By is49460 in forum Queries
    Replies: 3
    Last Post: 09-07-2013, 11:11 PM
  2. running select query in form delete event
    By suki360 in forum Programming
    Replies: 0
    Last Post: 03-11-2011, 10:11 AM
  3. on delete event in subform
    By suki360 in forum Programming
    Replies: 1
    Last Post: 03-08-2011, 03:45 PM
  4. Replies: 1
    Last Post: 06-22-2010, 03:15 PM
  5. Running a Delete (Records) Query on Close
    By NoiCe in forum Queries
    Replies: 1
    Last Post: 07-12-2009, 06:17 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