Results 1 to 5 of 5
  1. #1
    adray13 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2012
    Posts
    6

    Button on a form that forces you to select a set of criteria before running a macro

    Hi,



    I am a complete novice in Access, but I will try to explain this the best way I can...

    I have a table called afm_seat where one of the fields(columns) is named space budget. The space budget is the name of the scenario that the data belongs to. So, there can be many lines of data with the same space budget name because they are part of the same scenario. We will eventually be adding other scenarios with data as time goes on (they have not been created yet because it on a as needed basis).

    In the event where we need to scrap all the data for a scenario in the table I need to have a delete query that will delete all lines of data for a specific space budget. I know how to make delete query although, I do not know how set the criteria to be specified by the user without going into Design View each time and changing the criteria. Is there a way to allow the user to type the name of the space budget they want to delete upon running the query?

    After I create this query I need to have a button on a form(that I have already created) that runs a macro which runs the delete query(I know how to create a macro that runs a query) and the button will need to ask you to specify the space budget you would like to delete in the specific table(this is what I need help with). I don't know that a drop down box will be useful because we will be adding more space budget names over time (unless there is a way that it automatically populates new space budget names as you add them).

    So, in other words I need a button on a form that will ask you what space budget you want to delete in the afm_seat table and then delete all data where the space budget equals it.

    Thank you so much for any help!
    Last edited by adray13; 05-06-2013 at 04:41 PM.

  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
    I personally would use a form to have the user input the value. You can use a drop down, presuming the list can be queried from the database somewhere. At the very simplest you could use brackets:

    DELETE * FROM TableName WHERE SpaceBudget = [Enter Space Budget]

    But I don't like the lack of control with that method.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    adray13 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2012
    Posts
    6
    Thanks for your reply. How would I use a form to have them input the value?

  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
    You point the criteria in the query to the form (you can use the Build function). Then have a button on that form run your query, after testing for valid input or whatever is appropriate to your situation.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    If you want to control record deletion, need to also handle the action from keyboard Delete key. What I do:

    Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
    'Suppress default Delete Confirm dialog box.
    Response = acDataErrContinue
    'cancel the automatic delete operation
    Cancel = True
    MsgBox "Must click Remove Test button to delete test from sample." & vbCrLf & _
    "If sample is in closed accounting period, Delete/Remove test not permitted.", , "Delete"
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 14
    Last Post: 02-19-2013, 03:16 PM
  2. Replies: 13
    Last Post: 02-04-2013, 04:08 AM
  3. Running a module from a button in a form
    By sardamil in forum Modules
    Replies: 3
    Last Post: 05-01-2012, 10:59 PM
  4. running select query in form delete event
    By suki360 in forum Programming
    Replies: 0
    Last Post: 03-11-2011, 10:11 AM
  5. Replies: 1
    Last Post: 04-06-2009, 12:05 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