+ Reply to Thread
Results 1 to 6 of 6

Getting an error when deleting data in my employee database

  1. #1
    Registered User
    Join Date
    08-24-2019
    Location
    England
    MS-Off Ver
    2016
    Posts
    8

    Getting an error when deleting data in my employee database

    Hi please help with these code, this actual works fine, it's just that after the data has been deleted it gives me a run time error that says: Item with specified name not found and the code line that is color red below is highlighted.

    Seems because I deleted a record but still I don't want to have that error every time I delete something.


    Here's my code:


    Private Sub cmdDelete_Click()
    TRows = Worksheets("Data").Range("A1").CurrentRegion.Rows.Count
    Dim strDel
    strDel = MsgBox("Delete ?", vbYesNo, "Delete")
    If strDel = vbYes Then
    For i = 2 To TRows
    If Trim(Worksheets("Data").Cells(i, 1).Value) = Trim(ComboBox1.Text) Then

    Worksheets("Data").Range(i & ":" & i).Delete
    Worksheets("ImageData").Shapes("img" & Strings.Trim(txtEmpNo.Text)).Delete

    txtEmpNo.Text = ""
    txtEmpName.Text = ""
    txtAdd1.Text = ""
    txtAdd2.Text = ""
    txtEmail.Text = ""
    txtContact.Text = ""
    txtDesignation.Text = ""
    txtDOB.Text = ""
    txtSSS.Text = ""
    txtTin.Text = ""
    txtPagibig.Text = ""
    txtPhilhealth.Text = ""
    txtDOH.Text = ""
    txtVL.Text = ""
    txtVL1.Text = ""
    txtVL2.Text = ""
    txtSL.Text = ""
    txtSL1.Text = ""
    txtSL2.Text = ""
    imgEmp.Picture = Nothing
    Call prComboBoxFill

    Exit For
    End If
    Next i
    If Trim(ComboBox1.Text) = "" Then
    cmdSave.Enabled = False
    cmdDelete.Enabled = False
    Else
    cmdSave.Enabled = True
    cmdDelete.Enabled = True
    End If
    cmdNew.Enabled = True
    cmdClose.Caption = "Close"

    End If

    If Trim(txtEmpNo.Text) = "" Then
    cmdSave.Enabled = False
    cmdDelete.Enabled = False
    Frame2.Enabled = False

    Else
    cmdSave.Enabled = True
    cmdDelete.Enabled = True
    Frame2.Enabled = True

    End If
    End Sub

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Getting an error when deleting data in my employee database

    .

    Worksheets("ImageData").Shapes("img" & Strings.Trim(txtEmpNo.Text)).Delete



    Does your workbook have a sheet named : "ImageData" ?

    Does your workbook have a shape named : "img" located on sheet named "ImageData" ?

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Getting an error when deleting data in my employee database

    Maybe try:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Getting an error when deleting data in my employee database

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  5. #5
    Registered User
    Join Date
    08-24-2019
    Location
    England
    MS-Off Ver
    2016
    Posts
    8

    Re: Getting an error when deleting data in my employee database

    Yeah I have sheet named Image Data I think the problem is when I'm deleting a employee on our database that has no user image? How to go on that?

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Getting an error when deleting data in my employee database

    See post #3

+ 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. Locating and Deleting data pulled from a database
    By pynergee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-05-2013, 02:10 PM
  2. Employee Training Log Database
    By BeckyK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-28-2011, 01:56 PM
  3. Deleting all data in a database
    By stkh88 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2009, 12:55 PM
  4. Employee Database in access
    By Access Employee Database in forum Excel General
    Replies: 7
    Last Post: 07-23-2009, 07:50 PM
  5. Help with employee database
    By Timeclock in forum Excel General
    Replies: 3
    Last Post: 06-20-2009, 11:25 PM
  6. Employee expense database
    By phproxy in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 04-30-2009, 06:32 PM
  7. Deleting data in userform and database
    By Jennifer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2005, 09:05 AM

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