+ Reply to Thread
Results 1 to 6 of 6

VBA Form 'Delete' Command Button Code Ammendment

  1. #1
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    VBA Form 'Delete' Command Button Code Ammendment

    Morning,

    I have an invoicing form with a 'Delete' button which deletes rows of data (invoices).

    Is there anything I can add to my code to stop it from being able to delete Row 1 as these cells have my titles in and are not actually invoices.

    The code I'm currently using is:

    Please Login or Register  to view this content.
    Also,

    Ideally I'd like the delete button to not be active unless there is data populated in the form using the 'Find' button and ListBox for selection of data.

    I've attached my project for reference.

    Cheers
    Davo
    Attached Files Attached Files

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: VBA Form 'Delete' Command Button Code Ammendment

    Good morning davo3286

    You need to provide really concise instructions on how to do what it is you want to prevent.
    It may be immediately clear to you how this file works, as you built it.
    Seeing this for the first time today it wasn't obvious what I had to do to recreate your issue - which I need to do in order to fix it.
    I spent a minute or two on it and moved on. Given it's now been posted for over an hour, with a dozen views, it's clear others feel the same, which is a shame, as on the face of it, it seems like relatively simple fix.

    DominicB

  3. #3
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: VBA Form 'Delete' Command Button Code Ammendment

    Thanks Dominicb,

    Basically, once I complete the form and click the 'add' button it then stores the data on the 'MasterData' worksheet and closes the form.

    You can then reopen the form, click the 'find' button and then the data stored will appear in the listbox.

    Now click on any of the rows in the listbox and it will display the data in the form. From here you can amend the data or click the 'delete' button to delete whatever data is currently displaying in the form (which then deleted the row from 'MasterData').

    The problem is that you can just keep clicking the delete button and it will continue to delete rows until the 'MastaData' worksheet is empty.

    I was hoping to lock the first row in 'Masta Data' so that it cannot be deleted as this is my Titles field for what data is displayed below'.

    I hope this is a better explanation?

    Thanks
    Davo

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: VBA Form 'Delete' Command Button Code Ammendment

    Hi davo3286

    First off, I think that you need to add a command such as InvoiceList.ListIndex = 0 whenever the listbox is redrawn. This forces one of the rows to be recognised as the active row. It needn't default to row 0 either - you could quite easily capture the previous Listindex value and restore it at that point, but as I said, this needs to take place every time the listbox is updated.

    You will then need a line at the start of your DeleteButton_Click routine. Something as simple as :
    Please Login or Register  to view this content.
    should sort it - needless to say, this needs to come directly after the With Sheets... statement.

    HTH

    DominicB

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: VBA Form 'Delete' Command Button Code Ammendment

    More efficient to just test the listindex:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: VBA Form 'Delete' Command Button Code Ammendment

    Much appreciated - that's EXACTLY what I was hoping for!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Code to program a command button on a user form to advance to the next page...?
    By LuScannon in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-01-2017, 12:32 PM
  2. [SOLVED] Help on VBA code to delete a row in more than one table from a single command button
    By grahamlees in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2017, 05:46 AM
  3. VBA code to create command button. Print all sheets then delete command button.
    By Declamatory in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-15-2015, 05:18 PM
  4. [SOLVED] Userform: Code for DELETE on a command button
    By Gal403 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2014, 01:28 AM
  5. Require VBA code to Get data from data table to user form using command button
    By Srikanth H N in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2014, 04:17 PM
  6. Command Button Code to Delete Unprotected Cells Only
    By macky1730 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2011, 04:30 AM
  7. How to make a button in a user form invisible or delete it permanently throgh code
    By zarasandreas in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2010, 06:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1