+ Reply to Thread
Results 1 to 10 of 10

Code producing error, only on third run of Userform...?

  1. #1
    Registered User
    Join Date
    08-27-2009
    Location
    Milton Keynes
    MS-Off Ver
    Excel 2007
    Posts
    45

    Code producing error, only on third run of Userform...?

    I have created a Userform with various Listboxes, some interacting with others.

    I'm currently getting a rather frustrating error that decides to only show up on the third run of the UserForm.

    It will work perfectly fine with two runs of the Form (as in open, close then reopen) however, on the third attempt it will throw up an error (as attached) and will continue to do this for three runs of the Form and will work on the fourth.

    I'm not changing any piece of code within these runs, I don't understand why it works one minute and not the next...

    As mentioned, I have attached an image of the issue I'm having. Hopefully this provides enough info...

    Thanks for your time.
    Attached Images Attached Images

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code producing error, only on third run of Userform...?

    How are you opening and closing the userform?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-27-2009
    Location
    Milton Keynes
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Code producing error, only on third run of Userform...?

    Quote Originally Posted by Norie View Post
    How are you opening and closing the userform?

    by using the top right X within the Userform?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code producing error, only on third run of Userform...?

    So you are unloading the form not just hiding it, which I thought might be the problem.

    Apart from that I can't think of anything else, but an image of the error, and some of the code, isn't much to go on.

    Could you upload a sample workbook?

  5. #5
    Registered User
    Join Date
    08-27-2009
    Location
    Milton Keynes
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Code producing error, only on third run of Userform...?

    Quote Originally Posted by Norie View Post
    I can open and close the form multiple times without error.

    It's only when I try selecting items in the top listbox that I get errors in this sub.
    Please Login or Register  to view this content.
    Should I be doing anything else to replicate the error you are encountering?

    By the way, not seen ArrayList used much in VBA, to be honest I thought it didn't work after my own feeble attempts of implementing it.


    OK I have made an exact copy of the issue as attached.


    Example Sheet:

    Attachment containing private data has been removed by Moderator --6StringJazzer

    You'll have to run it a few times and click the first three options of the top listbox.
    Last edited by 6StringJazzer; 03-12-2019 at 10:00 PM.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code producing error, only on third run of Userform...?

    I can open and close the form multiple times without error.

    It's only when I try selecting items in the top listbox that I get errors in this sub.
    Please Login or Register  to view this content.
    Should I be doing anything else to replicate the error you are encountering?

    By the way, not seen ArrayList used much in VBA, to be honest I thought it didn't work after my own feeble attempts of implementing it.

  7. #7
    Registered User
    Join Date
    08-27-2009
    Location
    Milton Keynes
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Code producing error, only on third run of Userform...?

    Sorry, I tried to replicate it on a different userform but couldn't repeat the error. So I have copied the exact worksheet in a new attachment above (re-edited)

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code producing error, only on third run of Userform...?

    Does it help if you change the offending line to this?
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-27-2009
    Location
    Milton Keynes
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Code producing error, only on third run of Userform...?

    Quote Originally Posted by Norie View Post
    Does it help if you change the offending line to this?
    Please Login or Register  to view this content.
    Thanks Norie, that worked great.

    While I have your attention... Do you know how I can prevent it spiting out an error message when I select a Customer Ref in Listbox3 that isn't contained within Listbox1?

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Code producing error, only on third run of Userform...?

    Attachment containing private data has been removed by Moderator --6StringJazzer
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. [SOLVED] Code not producing a value
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-29-2013, 12:40 PM
  2. [SOLVED] Can't debug this code. The Arrays are producing a Subscript out of Range error
    By seigna in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-06-2013, 05:14 PM
  3. [SOLVED] Dount VBA code producing Run-time error '3075'
    By jeskit in forum Access Programming / VBA / Macros
    Replies: 13
    Last Post: 07-16-2012, 07:25 AM
  4. UserForm Code Error
    By Mooseman60 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2010, 09:05 AM
  5. VBA code suddleny producing an error
    By drgogo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2010, 07:18 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