|
-
May 15th, 2012, 07:32 AM
#1
Need help on Run-time error 3265
Hi guys!
So I'm a little rusty on VBA programming last time I did some VB was back in my college days :/
Here's my code:
Code:
Public Sub TraiterSample()
Dim ClefSampleRef As String 'Je suppose que c'est du texte
Dim cptSample As Long
Dim load_assays As dao.Database: Set load_assays = CurrentDb
load_assays.QueryDefs("Empty_Result_temp").Execute
Dim Populate_export As dao.Recordset: Set Populate_export = load_assays.OpenRecordset("Populate_export") 'rSample
Dim Result_temp As dao.Recordset: Set Result_temp = load_assays.OpenRecordset("Result_temp", dbOpenDynaset) 'rResultat
Do While Not Populate_export.EOF()
If ClefSampleRef <> Populate_export![Sample_no] Then
Result_temp.AddNew 'Ajoute un nouvel enregsitrement
Result_temp![Sample_no] = Populate_export![Sample_no]
Result_temp.Update
ClefSampleRef = Populate_export![Sample_no] 'Note la nouvelle clef de référence
cptSample = 0 'Reinitialise le compteur de valeur
End If
Result_temp.FindFirst ("[Sample_no]=""" & Populate_export![Sample_no] & """")
If Not Result_temp.NoMatch Then
Result_temp.Edit
cptSample = cptSample + 1
Result_temp.Fields("Au1_1ppm" & cptSample) = Populate_export![Au1_1ppm] 'Recopie la valeur dans le résultat dans la colonne voulue
Else
Error 5 'Cas impossible, soit il existait soit on l'a créé
End If
Populate_export.MoveNext 'Lit le sample suivant
Loop
Result_temp.Close: Set Result_temp = Nothing 'Ferme la source de données, libère la mémoire
Populate_export.Close: Set Populate_export = Nothing 'Ferme la source de données, libère la mémoire
Set load_assays = Nothing 'Libère la mémoire utilisé par l'objet db
End Sub
I'm having the error 3265 which says:" Item not found in this collection" on line:
Code:
Result_temp.Fields("Au1_1ppm" & cptSample) = Populate_export![Au1_1ppm]
Populate_export![Au1_1ppm] has a value in it so the problem must be with the .Fields thing. After browsing, I've found out that most of the time, this error is caused by a misspelled field name or a reference to a field that does not exist. I've checked everything related to this field name (Au1_1ppm which is btw gold values from lab assay certificates) and everthing is fine.
To wrap it up, this piece of code is going down my Populate_export query which is linked to a Excel sheet. If it find a re-assay for the same sample number (2 identical sample number with 2 values), it places the value of the re-assay in a specific field, get rid of the Doublon and put everything in my Result_temp table. That way, I only got one entry with all the values instead of having multiple entries for one sample number.
Do you guys have any idea as to why I'm having this freaking error ? Also, if there's a way to optimize that code I'm open to all suggestions. As I said, I'm back to being a rookie in this :P
Thx a lot
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|