+ Reply to Thread
Results 1 to 15 of 15

Deleting a record in a table, using VBA

  1. #1
    Forum Contributor
    Join Date
    02-10-2013
    Location
    Wolverhampton
    MS-Off Ver
    Excel 2010
    Posts
    101

    Deleting a record in a table, using VBA

    Hi, I have the following code (see below) which is supposed to select a record in a table when the user enters a customer ID in the textbox of a userform, and then clicks OK, for some reason however, it is not working, when I enter a customer ID in the textbox, and then when I click on OK, all that pop ups is the error message stating that the customer ID could not be found, even when the ID is in actual fact located in the table.

    My table starts in cell 7, (cell 6 if including headings) and there are 5099 records and there are 23 fields, so the table ends in column V.

    Could someone please help me

    Please Login or Register  to view this content.
    Last edited by nav505; 03-13-2013 at 01:13 PM.

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Deleting a record in a table, using VBA

    could you provide a sample in excel format?
    the FOR loop should start at 7

    Please Login or Register  to view this content.
    should be sufficient

    but if you just want to check if the ID is there then:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting a record in a table, using VBA

    Hi Nav505

    Check the Format of the Customer ID...what is it?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Forum Contributor
    Join Date
    02-10-2013
    Location
    Wolverhampton
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: Deleting a record in a table, using VBA

    Here is the sample workbook

    Book1.xlsm

  5. #5
    Forum Contributor
    Join Date
    02-10-2013
    Location
    Wolverhampton
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: Deleting a record in a table, using VBA

    The format is general, but I have tried changing it to number, and it still does not seem to work

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting a record in a table, using VBA

    Hi nav505

    You'll need to add Code Tags to your Post #1 before you'll get anymore feedback...

  7. #7
    Forum Contributor
    Join Date
    02-10-2013
    Location
    Wolverhampton
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: Deleting a record in a table, using VBA

    Hi jaslake, I have tried your code and it works, the only problem is when I enter a new record to the table, the code fails to pick it up, and just displays the error message that the customer ID does not exist, when it does! Can you please help me?

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting a record in a table, using VBA

    Hi nav505

    I didn't give you any Code yet but you could try this
    Please Login or Register  to view this content.

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting a record in a table, using VBA

    Hi nav505

    This Code works for me on your sample file
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    02-10-2013
    Location
    Wolverhampton
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: Deleting a record in a table, using VBA

    Hi jaslake, I tried your code and it works well, the only problem is when I add a new record (row) to the table the code does not pick it up, and instead the error message pops up stating the ID does not exist, when it actually does, could you please help me on this last problem? I would much appreciate it

  11. #11
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Deleting a record in a table, using VBA

    I modified your code and works ...
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    02-10-2013
    Location
    Wolverhampton
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: Deleting a record in a table, using VBA

    Hi RCM, the only problem with the code you have posted is that when a new record is added to the table, the code fails to pick it up? can you help me please?

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting a record in a table, using VBA

    Hi nav505

    This Code recognizes new records
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    02-10-2013
    Location
    Wolverhampton
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: Deleting a record in a table, using VBA

    Thank you so much

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting a record in a table, using VBA

    You're welcome...glad I could help. Thanks for the Rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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