PDA

View Full Version : How to autofill value base on result of a queried field



Obelik
05-25-2010, 06:36 PM
Hi,

I need help with this. I have a table with 6 distinct number variables (they are columns). I made a query to sum them accross row then return the absolute value (some variables have negative value). The results range from 0 to 5.

Now, I want Access to look at the results above and instead of returning 0 to 5, I want Access to return 0 for value </= 1 and 1 for value >1.

I don't know how to write the code telling Access to do that. I am learning how to write VBA code (first exposure to programing ever), but am stuck!

Can someone help?

Thanks!

OBP
05-26-2010, 04:45 AM
Obelik, welcome to the Forum.
You can do it in a Query, it doesn't actually require VBA code.
If you create a new Header like the one you used for the calculation and enter
zeroorone: iif([thenameofthecolumnwithabsinit]<=1, 0, 1)

Obelik
05-26-2010, 10:48 PM
I ended up doing it that way. It worked.

If you write VBA code, what would it look like? I'm learning here.

OBP
05-27-2010, 04:06 AM
Well you would normally do that on the form or Report in VBA and it would look like this
if me.[thenameofthecolumnwithabsinit]<=1 then
me.newfieldwithresult = 0
else
me.newfieldwithresult = 1
end if