+ Reply to Thread
Results 1 to 17 of 17

User form won't update correctly

  1. #1
    Registered User
    Join Date
    04-28-2014
    Location
    Florida
    MS-Off Ver
    Excel 2007, 2010, 2011 Mac. 2013,2016. I use 2011 and 2016 the most
    Posts
    90

    User form won't update correctly

    I made a userform to manage apartment buildings but I can't get some of the command buttons to work right. I have no problem adding a new job. It fills into the worksheet correctly. What happens is, when I type an apartment number such as 125 and hit previous apartment # button, the information is loaded into the user form. When I update the information and hit the update button it updates to the wrong row. The same thing with the next apartment # button. Another thing, if I just opened a user form and hit the update button it erases one of the rows. I've been working on this thing for a few days now and I've searched around for answers but I'm still stuck. I'm still pretty new with user forms but I'm trying to learn. I'm attaching the file with this. Any help would be great, thanks, Jim
    Attached Files Attached Files

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: User form won't update correctly

    Since I don't know your workbook like you do, the explanation you give me needs a little refining.

    If you could tell me specifically what to do, what to type, which button to push etc. and then what I will see and what you think I should be seeing, it would be helpful.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Registered User
    Join Date
    04-28-2014
    Location
    Florida
    MS-Off Ver
    Excel 2007, 2010, 2011 Mac. 2013,2016. I use 2011 and 2016 the most
    Posts
    90

    Re: User form won't update correctly

    Go to the start sheet tab. Click on start/ update job. User form will open up. Move are form out of the way so you can see the data table on sheet !. In the yellow box next to apartment #, get rid of the question mark and write 125. Click on the button labeled find previous apartment #. The user forum Will populate. Write anything you want to in the description/ comments yellow box. Click on update record command button. Look at where the data gets updated to on sheet one. it puts It in the top row. I would like the data only user form to get copied to the correct row that has the existing information already in it in this case it would be row Number three. The button, find next APT # does the same thing. I need whatever it is populated on the form, to go into its respective row on the data sheet When, update record button is pressed. Not that it should matter but I'm using Mac Office 2011 thanks again
    Last edited by Jamesera27; 01-19-2016 at 10:38 PM.

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: User form won't update correctly

    Okay try this code for the update record button.

    Let me know if you need help with anything else.
    Please do like you did above. Tell me how to recreate the issue, what the problem is and what you want to have happen.

    Please Login or Register  to view this content.
    Last edited by skywriter; 01-19-2016 at 11:54 PM.

  5. #5
    Registered User
    Join Date
    04-28-2014
    Location
    Florida
    MS-Off Ver
    Excel 2007, 2010, 2011 Mac. 2013,2016. I use 2011 and 2016 the most
    Posts
    90

    Re: User form won't update correctly

    I really appreciate your help, seems be working fine now. It's amazing how fast the response time is. There is one other question that I have. I noticed on the user form that the start and finish time is in decimal format. How what I make that display in the right format on the user form

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: User form won't update correctly

    Thanks for the rep. points.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-28-2014
    Location
    Florida
    MS-Off Ver
    Excel 2007, 2010, 2011 Mac. 2013,2016. I use 2011 and 2016 the most
    Posts
    90

    Re: User form won't update correctly

    Thanks a lot skywriter, I really appreciate all your help. You fixed in 10 minutes what I couldn't figure out in three days. Hopefully one day I'll be able to help people out too.

  8. #8
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: User form won't update correctly

    Let me know if you need anything else.

  9. #9
    Registered User
    Join Date
    04-28-2014
    Location
    Florida
    MS-Off Ver
    Excel 2007, 2010, 2011 Mac. 2013,2016. I use 2011 and 2016 the most
    Posts
    90

    Re: User form won't update correctly

    After trying it out more today with your code, i noticed:

    Go to the start sheet tab. Click on start/ update job. User form will open up. Move are form out of the way so you can see the data table on sheet !. In the yellow box next to apartment #, get rid of the question mark and write 125. Click on the button labeled find previous apartment #. The user forum Will populate with the first row of data for apt# 125. I click Next Apt# button and the form populates with the next row of data for apt# 125. When i update this form it returns the data to the previous row for Apt 125. I need the data in the form to update and return the data to the correct row in sheet 1

  10. #10
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: User form won't update correctly

    So tell me what all you want the form to do.

    Usually a button labeled next and previous will just move from record to record without regard to any particular information, meaning something like an apartment number. Wherever you are in a database, then hitting next will move to the very next record, not the next one with the same apartment number, and hitting previous will move to the record just before it, again the very next record before, not the one with the same apartment number.

    If you are on the very first record and you hit previous, nothing happens, hitting next on the last record nothing happens.

    So just let me know what you want to do, keeping in mind what do you want the behavior to be if you have no records, more than two records, etc.

    Maybe just a single button that searches for the first instance of a match, then the next, then the next, informing you when you are back to the first one again.

  11. #11
    Registered User
    Join Date
    04-28-2014
    Location
    Florida
    MS-Off Ver
    Excel 2007, 2010, 2011 Mac. 2013,2016. I use 2011 and 2016 the most
    Posts
    90

    Re: User form won't update correctly

    ok. i want whatever data i am looking at on the user form to be placed into the correct row on the database in sheet 1. yes the previous Apt# button does go to the previous record, and the Next apt# button does go to the next record. they work fine. the problem is as i explained in my last post. if i enter 125 into apt box and hit previous apt# it does show the first record on the form which is in row 3, now, when i go to next apt# it goes to the next info for 125 which is in row 9, which is different from the first one because they are 2 diff jobs with diff info. when i change the information on the user form which is the info for row 9 and press UPDATE , the data overwrites row 3 . it should be overwriting row 9 on the sheet. i don't know how else to explain it

  12. #12
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: User form won't update correctly

    Okay, you realize you have buttons labeled find next record and find previous record as well as find previous apt# and find next apt# I think that's where the confusion lies.

    No problem I'm looking at your code, give me a while to study it.

    One think I noticed right away is you have a variable at the top of the module.

    Please Login or Register  to view this content.
    Then in one of your procedures you have:
    Please Login or Register  to view this content.
    If you intend these to be the same variable, they are not.
    By having Dim lastrow in your cmdPrevious procedure it's a separate variable that can only be used within the procedure that it's declared in. Changing its value does not change the variable at the top. As soon as you hit the end of the procedure the variable is destroyed. The variable at the top is not changed from it's previous value.

    If you knew this and it's what you intended, I would advise again it as it's confusing. Make those in your sub procedures a different name so as to avoid confusion.

  13. #13
    Registered User
    Join Date
    04-28-2014
    Location
    Florida
    MS-Off Ver
    Excel 2007, 2010, 2011 Mac. 2013,2016. I use 2011 and 2016 the most
    Posts
    90

    Re: User form won't update correctly

    I'm still trying to learn VBA and some of the code I use is downloaded and restructured to meet my project. As far as the other 2 buttons Previous Record and Last Record,they seem to be working fine. The only way to tell is to try them out. Maybe Im missing something. If it's easier maybe attach the file after you check it out so i won't enter the data wrong. The important thing here is that the Data on the user form gets entered into the correct row on sheet 1. I appreciate your help.

  14. #14
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: User form won't update correctly

    Okay, here's what I found and here's what I have done.
    You have a public variable at the top of the module called currentrow.
    When you initialize the user form you are setting this variable to 2.
    When you click the previous apartment button and the code runs, the first thing it does is figure out which is the last row in sheet1 and assigns that number to the variable lastrow. Since you declared last row inside that sub procedure it has no effect on the same variable named lastrow at the top of the module.

    The next thing that happens is you are looping from the value of lastrow to 2 backwards via step -1.
    The issue is this:
    you are using currentrow as a counter.
    For currentrow = lastrow to 2 step -1

    You do not exit this loop anywhere, so the loop will always run down to 2, therefore currentrow will always have a value of 2 when this loop ends.

    The other thing is, you call this previous apartment number, but this procedure always loops from the bottom of the sheet up and will in actuality always find the first record, no matter how many are on the sheet. So I don't know what your intention is, but it's always going to find the first record.

    Your command next apartment number procedure loops from the first row to the last and will always find the last record no matter how many are there. The way it's set up I would label the first button command first apartment # and the second one command last apartment #.

    If you want the first apartment # I would loop from the top and exit the loop as soon as it finds that number and for the last one I would loop from the bottom and exit when it finds the first apartment which would be the last if there's more than 1 apartment number or the first if there's only 1.

    So what I did was this. I used a counter c for the loop and changed the current row number to equal c, but only when there's a match. Therefore the command add procedure can use the current row number to update the correct record on the sheet.

    You should study the code to see what I did and then you will see how you might have to change other code.

    If you have any questions let me know.
    Please Login or Register  to view this content.
    Last edited by skywriter; 01-20-2016 at 06:42 PM.

  15. #15
    Registered User
    Join Date
    04-28-2014
    Location
    Florida
    MS-Off Ver
    Excel 2007, 2010, 2011 Mac. 2013,2016. I use 2011 and 2016 the most
    Posts
    90

    Re: User form won't update correctly

    ok, i see how that works and it's definitely not what i want, especially if i have a sheet with 200 rows and the occurrence of a specific number is in the 75th row. i have spent the last day searching for what i need and still can't. the code i'm trying to find is this: lets say you open the excel program on your computer. At the top of excel is a quick search field with an arrow left and arrow right you enter what you want to search and it goes to it, hit the right arrow and it goes to the next occurrence, and so on. Left arrow does the opposite. That is what I need my form to doSnip20160121_1.png i tried to attach a picture of the button. Not important. I believe all versions of excel have the search field. Whatever code it uses i need the code for VBA to use it in my form

  16. #16
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: User form won't update correctly

    You can use the existing buttons. Find next apartment # searches from the beginning. The other button allows you to go backwards from where ever you are in the forward search process.

    Add this code:
    Please Login or Register  to view this content.
    Swap out the existing code with this:
    Please Login or Register  to view this content.
    I attached the file just in case.
    Type 125 where the question mark is and then use the find next apartment # button to go through the records forward and the other button to back up. Type another number into the box and start all over again.
    Attached Files Attached Files
    Last edited by skywriter; 01-22-2016 at 02:00 PM.

  17. #17
    Registered User
    Join Date
    04-28-2014
    Location
    Florida
    MS-Off Ver
    Excel 2007, 2010, 2011 Mac. 2013,2016. I use 2011 and 2016 the most
    Posts
    90

    Re: User form won't update correctly

    First of all I would like to say, WoW, You Nailed It! My headache is already subsiding. I will analyze your code and will use it again soon, and a lot. Once Again, Thanks A lot I wish I could Add More Reputation.

+ 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. User Form Update
    By Yorke181 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-24-2014, 10:52 PM
  2. Replies: 1
    Last Post: 08-28-2013, 05:04 PM
  3. Replies: 0
    Last Post: 01-08-2013, 06:03 PM
  4. Match new password to specific user and update list via custom user form
    By Sargekd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2011, 09:40 AM
  5. Filling form fields via worksheet dropdowns, user update via form, change form color
    By Demosthenes&Locke in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2010, 08:58 AM
  6. Listbox Update on user form
    By Irish_Griffin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-15-2009, 02:41 PM
  7. User Form Label not filling correctly
    By duckboy1981 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-10-2008, 05:34 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