Results 1 to 8 of 8
  1. #1
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286

    How to not add Record if User clicks a BUTTON


    hello i have a subform on my form, that are bound to a table. if a user clicks the "back" button, i do not want the record to be added to the table if there is a string anywhere in the subform textboxes. how would i go abotu this? thanks

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    It would seem to me that the record has already been added once they go off the record (click on a button). You will have to delete the record from the table. This should be simple enough as the current record will have the ID or PK so just run a query to delete it.

  3. #3
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    well the idea is i want the record automatically deleted if this button is clicked instead of manually removing it

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    There is no such thing as automatic - you have to program the button to do it for you. Either use VBA code or a macro to run a query which you have created - deleting the record where the pk = the pk on the form (the one just added).

    What else does the back button do?

  5. #5
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    i have an add record button and a back button, the back button just goes back to the previous form, the add record button should add the record (its got a few queries tied to it). if user hits back button i dont want the record to be added (thats what the add record button is for)

  6. #6
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    i understand the record gets added prior to clicking on the button, but how do i program the back button to also remove the record? i dont have a delete or duplicate query wizard on my version of access. can you help me create a delete query if thats the only choice? thanks

  7. #7
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Here is an example of a delete query. The "WHERE" condition will be set to something like WHERE primary-key-name = Forms!formname(!subformname)!primary-key-name. That way the query will delete the record that is current on you form, i.e. the one just added. (I hope you test these things before putting them into production!)

    You can put this into the VBA code on the OnClick event of your back button - either make it a real query with a name and use DoCmd.OpenQuery "xxx" or you can use DoCmd.RunSQL "insert sql here......"

    DELETE Table1.ID
    FROM Table1
    WHERE (((Table1.ID)=2));

  8. #8
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    thank you, that worked!

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

Similar Threads

  1. Replies: 0
    Last Post: 07-28-2011, 01:19 AM
  2. Replies: 4
    Last Post: 07-22-2011, 12:52 PM
  3. Replies: 10
    Last Post: 03-21-2011, 02:46 PM
  4. Automated Email Reports - monthly no clicks
    By Bamber in forum Reports
    Replies: 1
    Last Post: 05-12-2010, 12:34 PM
  5. Replies: 6
    Last Post: 02-09-2010, 07:53 AM

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