+ Reply to Thread
Results 1 to 7 of 7

VBA. Userform to retrieve data and then save to existing row and not create new row

  1. #1
    Registered User
    Join Date
    02-28-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    49

    VBA. Userform to retrieve data and then save to existing row and not create new row

    Hi,

    I'm working on a userform for Insurance project. I'm looking to pull back quotes into a form from the spreadsheet, modify them and write them back to the spreadsheet but not creating a new entry - in otherwords updating that record.

    I have the form working to add entries to the spreadsheet, and pulling them back in from a combo box, but need help with the code not to create a new row and update the current one.

    Insurance.xlsm

    Attached is the workbook so far.

    Any help in the right direction would be much appreciated.

    Many thanks,

    Dave

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA. Userform to retrieve data and then save to existing row and not create new row

    The way i handle this is, when the combobox change event fires, record the row of the Quote Reference selected. I use the Tag property to store the row number.
    Please Login or Register  to view this content.
    Then, in the OK button event, I use this row number to write the record back.
    Please Login or Register  to view this content.
    I also use a if-Then to determine whether the record is an edit or new.

    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    02-28-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: VBA. Userform to retrieve data and then save to existing row and not create new row

    Hi, Thanks for help. I've added the code... but not quite working.

    I may have entered things in the wrong place - it compiled ok though.

    I've added my amended workbook, if you have time to view the code i'd very much appreciate it.

    I'm relatively new to VBA so still learning.

    Insurance2.xlsm

    Many thanks,

    Dave

  4. #4
    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: VBA. Userform to retrieve data and then save to existing row and not create new row

    Hi Dave

    Does
    not quite working
    mean Automation Error?
    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.

  5. #5
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA. Userform to retrieve data and then save to existing row and not create new row

    OK, I think I have it now.

    The dropdown change event is getting called during update, so we have to declare a global variable to cancel the event.
    Attached Files Attached Files

  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: VBA. Userform to retrieve data and then save to existing row and not create new row

    Hi Dave

    I get an Automation Error when I try to run your Code.

  7. #7
    Registered User
    Join Date
    02-28-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: VBA. Userform to retrieve data and then save to existing row and not create new row

    Hi,

    Thanks for you help - Tinbendr. Its working well.

    I did run into one issue that if you modify one record and update then try alter another without closing the form first, some information is lost from the table. This isn't a big problem though as its likely we'll only be editing one record at a time.

    Appreciate you help.

    Dave

    - Jaslake, not sure why your receiving an error - the latest version added by Tinbendr works well.

+ 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. Replies: 3
    Last Post: 10-14-2013, 03:06 PM
  2. Use textbox in userform to retrieve data
    By Fogsta65 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-12-2013, 04:59 PM
  3. Create Next /Previous command buttons also Modify existing record in a Userform
    By rabalam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2012, 04:10 PM
  4. data save & retrieve macro
    By gsheets in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-04-2006, 03:52 AM
  5. Would like to retrieve data from spreadsheet to userform
    By Bucko in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-03-2006, 09:15 AM

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