Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2011
    Posts
    11

    Unanswered: Run query on form exit

    I'd like to run an update query when a user closes a form (a subform is the selection basis for a report (yes/no)). I have the query set up, I just need the correct VBA code to execute this. I would also like the user to be able to exit without access asking if they're sure they want to update the records.

    User checks "Services" to include in the report, clicks the report button, print report and subsequently exits form...


    Thanks so much!!

  2. #2
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    119
    To run a query use this code:

    Code:
    DoCmd.Hourglass True
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "QUERYNAME"
    DoCmd.SetWarnings True
    DoCmd.Hourglass False
    Regards
    JD

    Software-Matters

  3. #3
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    994
    Provided Answers: 2
    Air code from memory - this goes in the form's Close event:
    Code:
    Application.Warnings = False
    
    CurrentProject.Execute $SQLstatement
    
    Application.Warnings = True
    You might want to check the above suggestions against the help file.

    *EDIT*
    Or just use SoftwareMatters' idea - it looks better than mine!
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  4. #4
    Join Date
    Jun 2011
    Posts
    11

    Thanks!!!

    You guys rock! Worked like a charm!!

    Cheers!

Posting Permissions

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