Results 1 to 3 of 3
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Cmd button to run delete query (XP)

    I've built a very small Access application to maintain a shopping list for office supplies. It has one table, one query, one form, and one report. Simple. The application opens to display the supply order form (data entry). In the form footer I tried to put a command button that would launch a delete query. The idea is that when the supply order person has filled all the requests, she can just click the button to clear the table. The delete query shows up in the database window, and it works (I tried it).

    This is my first attempt to install a command button to run a query, and I've hit a snag. The wizard goes through all the steps, but when I get to the box where I expect to see my delete query listed, it's blank. What have I overlooked?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Cmd button to run delete query (XP)

    I don't know why you wouldn't see the query, but you can easily write the necessary code yourself:
    1. <LI>Open the form in design view.
      <LI>If you already have a command button, skip to step 5.
      <LI>Make sure the Wizard button on the Toolbox is off.
      <LI>Put a command button on the form.
      <LI>Modify the caption and the name of the command button (a name such as cmdClear is better than Command19.)
      <LI>Activate the Event tab of the Properties window.
      <LI>Select [Event Procedure] from the dropdown list in the On Click event.
      <LI>Click the ... to the right of the dropdown arrow.
      <LI>Complete the code as below, substituting the corrext names.
    Private Sub cmdClear_Click()
    DoCmd.OpenQuery "qryDeleteRecords"
    Me.Requery
    End Sub

    Note: the user will be prompted twice: to confirm execution of an action query and to confirm deletion of n records. If you want to avoid this, either put DoCmd.SetWarnings False above, and DoCmd.SetWarnings True below the OpenQuery line, or replace it by CurrentDb.Execute "qryDeleteRecords

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Cmd button to run delete query (XP)

    Once again, thank you, Hans! That does the trick!

Posting Permissions

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