+ Reply to Thread
Results 1 to 15 of 15

Userform Code Errors (broken by novice/fool)

  1. #1
    Registered User
    Join Date
    11-21-2013
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    20

    Userform Code Errors (broken by novice/fool)

    Hi All,

    Have only been using VBA for about a month and in all honesty most of the time I am completely lost and muddle my way through by trial and error looking at all the forum posts and add, alter, copy and delete code to suit (often in error due to ignorance). Unfortunately I am one of those people that decides to learn something new and jumps in with both feet and a complete lack of knowledge about what they are doing ... on the plus side, you guys get to show people like me the knowledge to strive for !

    Long story short, I created the attached workbook with a Userform to add new records and view and update existing records. Initially it worked fine and on opening with the "Update Records" button it would open the Userform with blank fields and on clicking the spin button would go to the first (or last) record which could then be updated. Unfortunately now however, I have done something to the code that effectively leaves the Userform broken. Ideally it would jump to the first saved record when opening and the add, update buttons etc would all work as intended, now they don't.

    If anyone knows how to fix the attached would be very much appreciated ... even better if you could tell me what I did wrong !

    Thanks for taking the time to read !
    Attached Files Attached Files
    Last edited by D.A.S; 11-22-2013 at 03:51 PM.

  2. #2
    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: Userform Code Errors (broken by novice/fool)

    Hello D.A.S.,

    I just starting looking at your workbook. I finally stop laughing after seeing your "Help Form" message. I give it a score of 10!
    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!)

  3. #3
    Registered User
    Join Date
    11-21-2013
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Userform Code Errors (broken by novice/fool)

    Hi Leith,

    There has to be a little humour in life ... I put that in there for the others who will use it at work (when I get it working properly). I figured it might break the monotony of work and put a smile on there face for a minute or two.

    Am guessing it had the desired effect !

  4. #4
    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: Userform Code Errors (broken by novice/fool)

    Hello D.A.S.,

    Add this code to your UserForm1 code. This will display the first record when the form is displayed.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-21-2013
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Userform Code Errors (broken by novice/fool)

    Hi Leith,

    I added the code to the UserForm1 code but now brings up the following error when the form is opened:

    Please Login or Register  to view this content.
    In the above " R = .SpinButton1.Value + 1 " is highlighted when I debeg ....Thoughts?
    Last edited by Leith Ross; 11-22-2013 at 06:19 PM.

  6. #6
    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: Userform Code Errors (broken by novice/fool)

    Hello D.A.S.,

    Do you have more than one UserForm loaded at a time? If so you need to change your this line...
    Please Login or Register  to view this content.
    To match the UserForm you want the macro to examine. UserForms(0) points to the first UserForm was loaded. If that UserForm loads another one, then UserForms(1) refers to the second form and so on.

  7. #7
    Registered User
    Join Date
    11-21-2013
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Userform Code Errors (broken by novice/fool)

    Hi Leith,

    Updated based on the advice in both of your posts and am pleased to confirm that the form now opens and populates automatically with the first record (I did have 2 Userforms open at the same time).

    Add, Save and Update command buttons on UserForm1 still not working but will have a play for a while and see if I can correct (or annihilate) before this part of the thread gets answered.

    Sorry to take up your time but the responses are very much appreciated!

  8. #8
    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: Userform Code Errors (broken by novice/fool)

    Hello D.A.S.,

    You are not taking up my time. I am here to answer questions. Post back with any questions or problems you have.

  9. #9
    Registered User
    Join Date
    11-21-2013
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Userform Code Errors (broken by novice/fool)

    Hi Leith,

    Problem was just old eyes .... I missed updating a couple of records to reflect the second UserForm.

    Everything now working as intended. The best part is I have learnt something new!

    Sincere thanks for your help.

    If I lived a bit closer I would shout you a beer !

    Regards ... Darryl

  10. #10
    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: Userform Code Errors (broken by novice/fool)

    Hello Darryl,

    You can raise a pint for me and say "Sláinte!". That will do just fine.

  11. #11
    Registered User
    Join Date
    11-21-2013
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Userform Code Errors (broken by novice/fool)

    One Query leith,

    Although the form is now populating and updating etc. I can't seem to get past the 100th record .... spin button stops at 100 even though I know there are another 60 or so records after that ?

  12. #12
    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: Userform Code Errors (broken by novice/fool)

    Hello Darryl,

    The Max property of any SpinButton defaults to 100. You can change this property anytime you like.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-21-2013
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Userform Code Errors (broken by novice/fool)

    Thanks Leith
    Just picked up your post while boarding a plane. Will try as soon as I return home on Sunday night

    Regards Darryl

  14. #14
    Registered User
    Join Date
    11-21-2013
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Userform Code Errors (broken by novice/fool)

    Hi Leith

    Back home and finally had the chance to try your last bit of advice which worked like a charm (as anticipated).

    Thanks for all the help .... and just so you know .. I followed your request and raised several pints in your honor although after the 5th (or 10th), "Sláinte!" turned into a slurred version of "Cheers".

    Regards
    Darryl

  15. #15
    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: Userform Code Errors (broken by novice/fool)

    Hello Darryl,

    Tapadh leat mo caraid!


    I think Robert Burns said it the best...

    And there’s a hand, my trusty fiere !
    and gie's a hand o’ thine !
    And we’ll tak a right gude-willy waught,
    for auld lang syne.

+ 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. Created a userform in VBA that worked beautifully yesterday and crashed Excel today!
    By willneal in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 10-31-2012, 11:47 AM
  2. [SOLVED] Average hours worked based on days worked during a pay cycle
    By jaycee66 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-14-2012, 06:27 PM
  3. Replies: 0
    Last Post: 05-14-2012, 05:36 PM
  4. Calculating basic hours worked, between a time range and premium hours worked
    By RoyLittle0 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-07-2012, 06:59 AM
  5. Replies: 0
    Last Post: 01-05-2012, 06:23 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