Jeg befinder mig nede i en underformular der har med prøvetagning af fisk at gøre, jeg skal have afgjort hvor mange fisk af samme art, længde, og område der alerede er taget Otolither (Øresten) af. Hvis der er findes der en eller records i en undertabel med egenskaben "Otolith" i et af felterne.
Den rutine der går ned og tæller ser således ud:
Private Sub SetCountOtolith(Year, Species, NAFO)
Dim cn As Connection Dim rs As ADODB.Recordset
Set cn = CurrentProject.Connection Set rs = New ADODB.Recordset
Select Case Sex Case "M" OtolithCountsM(Length) = OtolithCountsM(Length) + 1 Case "F" OtolithCountsF(Length) = OtolithCountsF(Length) + 1 Case Else OtolithCountsU(Length) = OtolithCountsU(Length) + 1 End Select
rs.MoveNext Loop
rs.Close Set rs = Nothing
End Sub
SQLStringIndividualSampleCount laver en SQL der udvælger de korekte records der ligger i flere forskellige tabeller.
Når denne rutine har kørt så retter Acces selv den record jeg står i så den bliver lig med den sidste record der har en prøve af typen "Otolith", det er ikke fordi den flytter record, den kopierer den forige og overskriver de værdier jeg havde før.
Hvad #&%"!! laver den, og hvordan løser jeg problemet?
Jeg har prøvet at lege med adOpenStatic i stedet men det ser ikke ud til at gøre nogen forskel.
well its hard to say when we dont have the complete code! Your best bet is to place a breakpoint in th ecode and step you rway through th eprogram so that you can see what is happeneing and also what exactly causes the error!.
Hvad er OtolithCountsM, OtolithCountsF og OtolithCountsU? Er det funktioner? Hvordan ser de ud?
Du kan prøve at erklære alle dine funktions-parametre som ByVal f.eks. sådan: Public Funktion OtolithCountsF(ByVal Length as single) ...
Derved føres værdiændringer ikke med tilbage.
Så vidt, jeg kan se, så skrives der ikke til recordsettet, hvorfor dbOpenStatic bør benyttes (adOpenDynamic er i det hele taget den langsommeste cursortype - hvis der skal redigeres bør du bruge adOpenKeyset).
Hi again, I was off work for a couple of days here.
I have not solved the problem, but I have a workaround. The problem seems to occur because the table that is the basis of the form in question also is part of the recordset I need to querry to find out how many similar records there are.
OtolithCountsM etc. are arrays that keep the number of done Otoliths per lengthgroup (whole centimeters) in memory so I don't need to querry the database every time.
While I was testing this out I had a button that called the initialization routine while the form was open, then the problem occured. But when I changed to calling the initialization routine on the OnOpen event there was no problem.
In any case, the routine needs to be an OnOpen routine so my problem is in a way solved, except that I'd like to know why the h... I can't querry a table that is opened by a form without getting that error.
The sugestion of using adOpenStatic did and calling ByVal did not pan out.
I would need to see the WHOLE database before I can give a reason for the problem you are having. Normally there should be no problem you querying the table a form is based on!
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.