VBA calculation

  • Thread starter Thread starter Martine
  • Start date Start date
M

Martine

Hi,
I'm new to Access and I'm trying to make a calculation in
VB. Here's my pseudocode:
Returns the total
variable x = 0;
If [QID] in (58,59,61,62,64,65,67,68,69) And
([tblAnswer.Ans1]=-1))
Or (([QID] in (60,63,66) And ([tblAnswer.Ans2]=-1))
,1,0

then X+= 1;

I'd like X to be stored in a field in another table. How
and where would I program this? I have experience in C++
but not in VB.
Thanks in advance.
 
Hi
Can you be a bit more specific about where [QID] and [tblAnswer.Ans1] come
from, and how are they related (does tblAnswer have a [QID] in every
record?)

Is this to be performed for the records displayed on a form, or are you
processing the contents of a table?
Is this a function where you will be passing in the X, QID and Ans variables
(ie a cummulative addition function), or would you like it to loop over a
set of records?
Do you want the records to be filtered, and if so how? (if records on a form
then may not be relevant...)
When returning X where and how do you want it stored? eg if you do this sum
multiple times how would you like it to operate?

Set out how the data is laid out, what functionality you want, and we can
tell you how to do it and where to put the code.

As a first step though here are some pointers:

declaring x:
dim x as integer (assuming you will only ever be adding 1 to x, otherwise
make it x as variant)
x = 0 ' initialise

Select/Case statement examples below:
Select Case QID
Case 58,59,61,62,64,65,67,68,69 '*** note you can use "to", eg 5 to 15. May
be relevant if you only supplied a small example
if (tblAnser.Ans1 = -1) then
x = x + 1
endif
Case 60,63,66
if (tblAnser.Ans2 = -1) then
x = x + 1
endif
End Select

regards
A
 
Back
Top