Results 1 to 5 of 5
  1. #1
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116

    Delete button not working if there is code in onCurrent

    I have a form with some text and combo boxes and onCurrent event of the form, I have set actions for textboxes based on values in combobox. The form gets data from a table. For example, if in the comboBox, the value is "Yes", then a textbox will be enabled onCurrent event, if the value is "No", then the textbox is disabled onCurrent event.

    Now I also have a delete button on a form(The delete button is a macro. I used the default access macro). I know this sounds strange, but if the onCurrent code is not commented out, then the delete button acts weird. The button usually asks a confirmation msg asking if I really want to delete one row. But this confirmation msg does not pop up if the onCurrent code is present!!!!

    Any ideas why onCurrent and the delete button needs to have a connection?

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    are you deleting the current record? try writing the one-liner in code to delete it, then requery the form with another line of code. does it still happen?

  3. #3
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    I manually coded it, but I don't like how it looks. I mean if I use the macro, then the current record gets deleted and I am automatically taken to the next record. If I code with a one-liner, the current record gets deleted, but I am not taken to the next record. I just get #deleted in all my fields.

    Umm, sorry to trouble, but are there any sample codes?

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    I'm surprised that this code is not found on the net more.

    Code:
    Dim I As Long
    I = Me.CurrentRecord
    docmd.runcommand(accmddeleterecord)
    Me.Requery
    DoCmd.GoToRecord acDataForm, Me.Name, acGoTo, I
    #DELETED will always be in the form unless you requery it. But requerying it always takes you back to rec #1. Hence, the above code is necessary.

  5. #5
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Oh this code works! Thanks!

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

Similar Threads

  1. Delete SQL statement not working properly
    By Alexandre Cote in forum Programming
    Replies: 3
    Last Post: 10-18-2010, 12:56 PM
  2. Delete query button?
    By jpalk in forum Queries
    Replies: 2
    Last Post: 10-14-2010, 09:12 AM
  3. Replies: 0
    Last Post: 04-08-2010, 12:22 PM
  4. Button on form to delete all records
    By bbylls in forum Forms
    Replies: 2
    Last Post: 12-08-2009, 12:38 PM
  5. Add/Delete Button
    By ocemy in forum Forms
    Replies: 1
    Last Post: 03-29-2009, 08:08 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