Results 1 to 9 of 9

Thread: [RESOLVED] Error 35600 ListView Index Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2020
    Posts
    5

    Resolved [RESOLVED] Error 35600 ListView Index Problem

    Hi!
    I'm new at this forum, and I'm desesperate with a code I'm writing.. also... I'm a lawyer, so please be gentle with the explanations.
    So the thing is, that I'm triying to make a project that allows the user to save a lot of information, and edit it or add new. For this, I'm using many Forms, and some of those forms are "connected" to other.
    For example:
    Form: RegPMA (have a multipage with nine pages)
    The page 1, does not give me any trouble.
    But the page 2: Controls: ListView1, CommandButton1 (Editar)
    When the user click in the CommandButton1, calls other Form(RegContaminantes) and leaves Form(RegPMA) behind.
    RegContaminantes Controlls: Five TextBox, one Combox, and three CommandButtons.

    When the six controlls of RegContaminantes are filled, then the user is allow to save the value of those controls by clicking in the CommandButton2, and I need to save those values on three diferent sheets: "Parámetros"; "Datos" and "PMA", as well as saves the new values on the ListView of the previous Form (RegPMA)

    First, it saves it in the 1rst sheet ("Parámetros"), then Unload Me (RegContaminantes), and that makes RegPMA to be active again, wich makes to refresh the ListView content, viewing the new register of Sheet("Parámetros"), wich makes those valuse to be saved in the second sheet("Datos"), but all the values in one cell. Then, it should save the values in the third sheet("PMA").

    My problem, is in the process of saving the values, in the third sheet.. not even in the listview!
    I need the values to be saved in Sheets("PMA").Range("J2:O2").
    The thing is, that I need that every listItem in the listview of RegPMA, be saved in a new row. But I only get to be saved one item, and no more.

    One more thing: Of course, there is not all of the things I describe in one Macro, but in many...
    When the macro that saves in the first and second sheets, is close to the end, calls the DobleGuardadoContaminates Macro.

    This is the part of the Code in wich the error is... would yo help me find it, please?

    Code:
    Sub DobleGuardadoContaminantes()
    Dim NuevaFila
    Dim Rango As Range
    Dim i As Integer
    
    Set Rango = Sheets("PMA").Range("A2").CurrentRegion
    NuevaFila = Rango.Rows.Count + 1
    For i = 0 To RegPMA.ListView1.ListItems.Count - 1
        ThisWorkbook.Sheets("PMA").Range(NuevaFila, 10).Value = RegPMA.ListView1.ListItems.Item(i)
        ThisWorkbook.Sheets("PMA").Range(NuevaFila, 11).Value = RegPMA.ListView1.ListItems.Item(i).SubItems(1)
        ThisWorkbook.Sheets("PMA").Range(NuevaFila, 12).Value = RegPMA.ListView1.ListItems.Item(i).SubItems(2)
        ThisWorkbook.Sheets("PMA").Range(NuevaFila, 13).Value = RegPMA.ListView1.ListItems.Item(i).SubItems(3)
        ThisWorkbook.Sheets("PMA").Range(NuevaFila, 14).Value = RegPMA.ListView1.ListItems.Item(i).SubItems(4)
        ThisWorkbook.Sheets("PMA").Range(NuevaFila, 15).Value = RegPMA.ListView1.ListItems.Item(i).SubItems(5)
    Next i

    (All of this is part of the Form(RegContaminantes) Code, and it should use values of the ListView in a previous form. The problem, is that the loop For..To it's not working, because as I told you, only saves the last item entered, as if the macro would not doing the job of asign one value in each loop to "i", and it only asgins the last value. The ListView.ListItems.Count makes no difference, and the Error 35600 "Index out of bounds" is whats shows me, I would understand that it could not recognize the index because is in other form, but I did it in a previous couple of forms! I don't understand why in this two, now I have this problem)

    I hope its understanble, English is not my native language.
    Sorry for any trouble, and please help me!
    Magno

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,971

    Re: Error 35600 ListView Index Problem

    NuevaFila = Rango.Rows.Count + 1
    looks like this should be within the loop else every row from the listview will be written (overwritten) to the same row in the worksheet, else use the value of i to increase the offset from the original row
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2020
    Posts
    5

    Re: Error 35600 ListView Index Problem

    Thankyou for your answer.
    I just tried, and still showing me the 35600 "index out of bounds" error

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,971

    Re: Error 35600 ListView Index Problem

    post a sample of your workbook, zip first
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2020
    Posts
    5

    Re: Error 35600 ListView Index Problem

    Ok, thank you!
    Attached Files Attached Files

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,971

    Re: Error 35600 ListView Index Problem

    For i = 0 To QLV - 1
    when in ran the code qlv had a value of 0 so it would try to loop from 0 to -1, anyhow listitems.items(0) will give index out of bounds as it is 1 based, so try
    Code:
    For i = 1 To QLV
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2020
    Posts
    5

    Re: Error 35600 ListView Index Problem

    I did it, but now it only saves the last item, and no other. Actually, triying to avoid this, is that I hit the 35600.
    So, do you have any more advice, please?

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2020
    Posts
    5

    Re: Error 35600 ListView Index Problem

    This is the thing:

    Code:
    NuevaFila2 = Rango.Rows.Count
    
    For i = 1 To RegPMA.ListView1.ListItems.Count
        NuevaFila2 = NuevaFila2 + 1
        ThisWorkbook.Sheets("PMA").Cells(NuevaFila2, 10).Value = RegPMA.ListView1.ListItems.Item(i)
        ThisWorkbook.Sheets("PMA").Cells(NuevaFila2, 11).Value = RegPMA.ListView1.ListItems.Item(i).SubItems(1)
        ThisWorkbook.Sheets("PMA").Cells(NuevaFila2, 12).Value = RegPMA.ListView1.ListItems.Item(i).SubItems(2)
        ThisWorkbook.Sheets("PMA").Cells(NuevaFila2, 13).Value = RegPMA.ListView1.ListItems.Item(i).SubItems(3)
        ThisWorkbook.Sheets("PMA").Cells(NuevaFila2, 14).Value = RegPMA.ListView1.ListItems.Item(i).SubItems(4)
        ThisWorkbook.Sheets("PMA").Cells(NuevaFila2, 15).Value = RegPMA.ListView1.ListItems.Item(i).SubItems(5)
    Next i
    Thank You!!!

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,971

    Re: [RESOLVED] Error 35600 ListView Index Problem

    yes i picked that in post #2
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width