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
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
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
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
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?
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