Hello,
I have been trying to migrate some code I have written so I can use the advantages of Collection items in several forms I programmed in Access 2002. I was using an array list to collect information from a machine part and its resulting defect, then display a small summary of all parts as well as general information about the machine being repaired.
Now, most of the transition has gone without problems, however, I have hit a snag. When I try to list the collection items in the textbox, they reuse to list correctly. Here is the code I have done (displays information, just not how I want it)
Public Function creer_liste_piece_defaut(x As Integer)
'If condition: Si c'est la première fois que on fait appel à a fonction (controllé par les variables)
'la première condition est effectué. Sinon, la liste type "array" est augmentée en taille, tout en preservant
'les valeurs déjà entreés. La taille de cette liste est établit par la fonction qui fait appel à elle.
Dim y As Integer
'Création de la liste
'On s'arrete quand le nombre maximal de pieces est achevé
Do Until x > PieceDefaut.Count - 1
y = x + 1
If (est_Compresseur = True) Then
txtPieceDefaut = txtPieceDefaut & "---------------------" & vbCrLf & "Pièce: " & PieceDefaut.Item(x) & vbCrLf & _
"Défaut: " & PieceDefaut.Item(y) & vbCrLf & ""
'txtPieceDefaut = txtTransition & txtPieceDefaut
End If
If (est_Rechauffeur = True) Then
txtPieceDefaut = txtPieceDefaut & "" & vbCrLf & "Symbole: " & PieceDefaut.Item(x) & vbCrLf & "Défaut: " & _
PieceDefaut.Item(y) & vbCrLf & " --------------o------------" & vbCrLf & ""
End If
x = x + 2
Loop
End Function
Where PieceDefaut is the collection, and txtPieceDefaut is the string that contains the data outputted to the textbox. Now if I remove the txtPieceDefaut right after the = sign, all it does is display the current item being manipulated (when I use debug.print it display all the items, however), but if I leave it as it is, then it displays the information this way:
Sample output:
L'information suivant sera enregistrée dans la base de données:
Utilisateur: Bruno
Date d'intervention: 22/04/2011
Compresseur: 12/12
---------------------
Pièce: CLAPET <----The first item is repeated twice
Défaut: CASSE AVANT
---------------------
Pièce: CLAPET
Défaut: CASSE AVANT
--------------------- <---If I add another item, then ALL this
Pièce: STATOR is copied and displayed along with the new
Défaut: DEFAUT D ISOLEMENT item.
I have tried several "solutions" but all seem to only compound the problem, not fix it. What I was thinking (since I need the collection to allow users to delete data from it or modify before saving the machine repair data to the database, with the array I just had them reset all and start over, but that is not very productive in the long run) of doing was to use the collection.items property to assign it to an array, then display the array in the textbox, then manipulate the collection as so, then when I update the information, transform it to an array, rinse and repeat... yet this seems like a redundant way to do it. And I'm not sure if it will work (writing it as we speak).
I am open to suggestions, thanks in advance!