+ Reply to Thread
Results 1 to 19 of 19

Code to Seacrh and Delete database records on UserForm

  1. #1
    Registered User
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Code to Seacrh and Delete database records on UserForm

    G'day Excel Gurus,

    I'm new to VBA and creating UserForms. I am in the process of developing a pers data and NOK register for my workplace. I have set up a userform where the data can be entered and on pressing a save button on the userform, the data is stored in a worksheet. That works fine.

    What I need is advise on how to create a 'search' code and a 'delete' code for two userforms. One userform will be used to retrieve all the data based on a seven digit employee ID number in order to edit or update the info. The other userform is to delete all record of the person. Sounds simple enough, but I cant figure it out (being new to VBA)

    Any help is greatly appreciated.
    Last edited by Fogsta65; 07-30-2013 at 12:37 AM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Little help!!

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code to Seacrh and Delete database records on UserForm

    Hello Fogsta65,

    Welcome to the Forum!

    I changed your title to match your question. Can you post a sample of a workbook with sensitive and or personal information redacted?

    How To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.

    File Manger Picture
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Code to Seacrh and Delete database records on UserForm

    Hi Leith,

    Tried to upload the file but it says its too big. Even tried zipping it.....

    Thanks for the title change.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code to Seacrh and Delete database records on UserForm

    Hello Fogsta65,

    You're welcome. Even zipped the file won't upload? Are you getting any messages as to why it won't?

  6. #6
    Registered User
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Code to Seacrh and Delete database records on UserForm

    It just says the file is too big. I'm at work and on a network that does not allow uploads of more than 4meg I'm guessing.

    I'll email it home and upload from there.

    Thanks for you patience.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code to Seacrh and Delete database records on UserForm

    Hello Fogsta65,

    If there is no sensitive information in the workbook, perhaps you could upload it to file sharing sight like MediaFire. Nevermind, if the file is too big for network that option won't work.

  8. #8
    Registered User
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Code to Seacrh and Delete database records on UserForm

    Damn... cant even send it home to myself....

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code to Seacrh and Delete database records on UserForm

    Hello Fogsta65,

    If you have a flash drive, copy the file to that and then upload it.

  10. #10
    Registered User
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Code to Seacrh and Delete database records on UserForm

    Hi Leith,

    I have created the database for staff addresses and emergency contacts using userforms for initial data entry, amendments and deletions. I've worked most issues out myself but I'm having a mental blank with the 'delete record' function. My code will only delete from one worksheet called "Recall". I need the function to also delete the same row (person) from sheets called "Staff" and "PEC". The row to delete is derived on the userform using a cmb EMPL ID box that is unique to each person. A problem I also experience is when I click 'NO' to the "are you sure you want to delete" prompt... it still deletes the row from the main sheet. Here is what I've got:
    Please Login or Register  to view this content.
    Any help, as usual, is greatly appreciated.
    Last edited by Leith Ross; 08-05-2013 at 01:22 AM. Reason: Added Code Tags

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code to Seacrh and Delete database records on UserForm

    Hello Fogsta65,

    This should take care of the problems.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Code to Seacrh and Delete database records on UserForm

    Thanks Leigh,

    On deeper thought, the reason the rows are not deleting from the other two worksheets is because I've just put an equals function in "PEC" and "STAFF" to read the "RECALL" spreadsheet. thats why it will delete from "RECALL" but leave "#REF" in the other two. How would I expand my cmdADD function to include parts of the userform to PEC and STAFF?

    Also, the "Are you sure you want to delete".... still deletes even tho I click NO.

    Thanks for your speedy assistance.

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code to Seacrh and Delete database records on UserForm

    Hello Fogsta65,

    I tested the code before posting it. The message box works correctly. Did you use the macro I posted?

  14. #14
    Registered User
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Code to Seacrh and Delete database records on UserForm

    Yes mate. Copied and pasted exactly.... There are some other codes on that form that retrieve data (which I have a question about), and a close button. Could they be interferring with the "Are you sure?" NO button?

  15. #15
    Registered User
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Code to Seacrh and Delete database records on UserForm

    Hi Leigh,

    I've got everything working perfectly now, with the exception of the "Are you sure you want to delete this record" YES / NO. Clicking NO still deletes the record.

    John

  16. #16
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code to Seacrh and Delete database records on UserForm

    Hello John,

    Sorry I am get back to you late. This will work. I forgot to add an exit from the macro when the user answers no.
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Code to Seacrh and Delete database records on UserForm

    Thats it!! I couldnt see that either. Works a treat now. Thanks greatly for that.

    One more thing, if you know, the search mechanism is a combo box. Once all my data is in, the combo box will show approx 100 employee IDs to select from. Is there a way to just TYPE the employee ID in? I've notice when I just type an employee ID in, it does nothing. The number must be selected from the dropdown combo box....

    Your thoughts.

  18. #18
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code to Seacrh and Delete database records on UserForm

    Hello John,

    Is this an ActiveX Combo Box?

  19. #19
    Registered User
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Code to Seacrh and Delete database records on UserForm

    I dont know what an ActiveX combo box is. I just selected a dropdown box from the toolbox in the userform design area.

+ 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. Add/edit/delete records userform
    By kryt0n in forum Excel General
    Replies: 7
    Last Post: 09-10-2018, 11:49 AM
  2. Replies: 1
    Last Post: 01-03-2013, 01:13 AM
  3. Userform - search database for matching records, find next if more than one record
    By beaterfred in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-02-2012, 11:56 AM
  4. Userform Search Database code
    By dcompagnone in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2010, 05:27 AM
  5. [SOLVED] how do i delete multiple records from my database
    By AUSTINJ in forum Excel General
    Replies: 1
    Last Post: 05-15-2005, 06:12 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