I have to calculate the sum of a field in a while loop but after an iteration the variables credit1,credit2,sum1 and sum2 are reset (take the value 0).
I don't know where I'm wrong.
Can you help me ?
ok, leave it at that, it was a simple question ...
I was going to say that I don't see a wend to finish your do while statement.
but then I thought, hold on a minute, I don't recall ever seeing a recordset loop with do while in it.
Now I'm not saying it can't be done with a do while statement I'm saying I've never seen it done with do while statement so I may be getting an education here!
Have you declared "Option Explicit" at the beginning of your module?
I see you have declared several variables as 'Public.' I suppose you are aware of the dangers of using 'Public' variables?
Now to that subject, I see no declaration for the variables credit1 and credit2. Are they Textbox Controls (try putting them in brackets: [credit1])? Where do they reside? And is this place tied somehow to your module?
Why? Why all this? What's the big picture of what you are trying to accomplish? Looking at it, it all just seems convoluted and incorrect.
1. You are deleting a table (calcmed) then building it again. What does that table do for you that just building a query or just looping through data can't help you with?
2. I don't think your "static" tables are properly structured:
Code:
...
& " FROM materii INNER JOIN [note] ON materii.codm = note.matern " _
& " WHERE Mid(Str(matrn), 5, 2) = Mid((Str(anadmm)), 3, 2) " _
& " AND (note.ns1e <> 0 OR note.ns1v <>0 OR note.ns2e <> 0 OR note.ns2v <>0 OR note.np1 <>0 OR note.np2 <>0) " _
...
2a. You shouldn't extract data from data in fields. If matrn and anadmm contain a 2 character code inside them, then that 2 digit code should be stored seperately from the other data in matrn and anadmmm.
2b. You shouldn't numerate, prefix nor suffix field names. All the data in those note fields (e.g. note.ns1e, notens1v, note.ns2e, etc.) should go into another table with fields to store the number, prefix and suffix data now encoded in the field names.
3. Comment your code. A lot of the answers to my questions might be helped with commenting your code. When you have that much code you really need to document the general thinking and then the main components so that people who come later and try and work with this (including yourself) know what you are thinking.
Again, what's all this for? It seems you are coding around prior errors and building something that could be implemented in a simpler manner.
Have you declared "Option Explicit" at the beginning of your module?
I see you have declared several variables as 'Public.' I suppose you are aware of the dangers of using 'Public' variables?
Now to that subject, I see no declaration for the variables credit1 and credit2. Are they Textbox Controls? Where do they reside? And is this place tied somehow to your module?
I see two recordsets: rs_calcmed and rscalcmed.
I don't see where rs_calcmed comes from (no recordset open, no declaration of Access object type - table or otherwise). Could this be a typo?
Why? Why all this? What's the big picture of what you are trying to accomplish? Looking at it, it all just seems convoluted and incorrect.
1. You are deleting a table (calcmed) then building it again. What does that table do for you that just building a query or just looping through data can't help you with?
2. I don't think your "static" tables are properly structured:
Code:
...
& " FROM materii INNER JOIN [note] ON materii.codm = note.matern " _
& " WHERE Mid(Str(matrn), 5, 2) = Mid((Str(anadmm)), 3, 2) " _
& " AND (note.ns1e <> 0 OR note.ns1v <>0 OR note.ns2e <> 0 OR note.ns2v <>0 OR note.np1 <>0 OR note.np2 <>0) " _
...
2a. You shouldn't extract data from data in fields. If matrn and anadmm contain a 2 character code inside them, then that 2 digit code should be stored seperately from the other data in matrn and anadmmm.
2b. You shouldn't numerate, prefix nor suffix field names. All the data in those note fields (e.g. note.ns1e, notens1v, note.ns2e, etc.) should go into another table with fields to store the number, prefix and suffix data now encoded in the field names.
3. Comment your code. A lot of the answers to my questions might be helped with commenting your code. When you have that much code you really need to document the general thinking and then the main components so that people who come later and try and work with this (including yourself) know what you are thinking.
Again, what's all this for? It seems you are coding around prior errors and building something that could be implemented in a simpler manner.
What @June7 said. Debug the code and step through it line by line -- you will come to your solution doing that a lot faster than we will trying to digest all of that code in the post.
What @June7 said. Debug the code and step through it line by line -- you will come to your solution doing that a lot faster than we will trying to digest all of that code in the post.