Results 1 to 12 of 12

Combo box Additem - Run-time error - Invalid argument

Threaded View

Whited3 Combo box Additem - Run-time... 11-28-2008, 11:45 PM
royUK You really should design your... 11-29-2008, 04:50 AM
Whited3 Thanks Roy. The use of... 11-29-2008, 04:59 PM
Norie Mark And it's really a bad... 11-29-2008, 12:33 PM
Andy Pope The error is caused by you... 11-29-2008, 01:52 PM
Whited3 Thanks Andy. That's correct;... 11-29-2008, 05:08 PM
Whited3 Bad as in "improper use" or... 11-29-2008, 05:00 PM
royUK Please remember to always use... 11-30-2008, 04:17 AM
Andy Pope Actually in my code example... 11-30-2008, 05:22 AM
royUK Hi Andy I had wondered if... 11-30-2008, 05:43 AM
Andy Pope Morning, I agree you would... 11-30-2008, 05:46 AM
Whited3 Thanks Guys. Unfortunately... 11-30-2008, 05:28 PM
  1. #1
    Registered User
    Join Date
    11-28-2008
    Location
    Brisbane
    Posts
    8

    Combo box Additem - Run-time error - Invalid argument

    Hi,
    New to the forum so please go easy

    I've written an Excel (using 2007, compatibility mode to 2003) app for our stock control. Basically it's a protected stock sheet which the user adds/removes stock via a form.

    When the user runs the form the following code loops through the stock list header adding item names to a combo box. Problem is I get a run-time error if there's more than 60+ items but while the error always occurs, it happens at different places in additems.

    Run-time error '-2147024809 (80070057)
    Invalid argument.

    In the code I've allowed a loop to 1000 items but in reality they'll be no more than 150.

    Private Sub UserForm_Initialize()
    'Add the stock item names to the combobox.
    Blank_Items = 0
    For i = 2 To 1000
    If Worksheets("Stock List").Cells(4, i).Value = "" Or Worksheets("Stock List").Cells(4, i).Value = 0 Then
    Blank_Items = Blank_Items + 1 'Count consecutive blank items.
    GoTo Skip_Item 'If blank, don't add to list.
    End If
    
    With cbStock_Item
        .AddItem Worksheets("Stock List").Cells(4, i).Value, i - 2 'Add each item name from the stocklist and index from place 0 in listbox.
    End With
    Blank_Items = 0 'Resets the blank counter as a valid item was found.
    Skip_Item:
    If Blank_Items = 3 Then '3 blanks and assume at the end of the items.
    GoTo No_More_Items
    End If
    Next i
    No_More_Items:
    End Sub
    Looking forward to some sage advice.

    Cheers,

    Mark
    Last edited by dominicb; 11-29-2008 at 01:50 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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