PC Review


Reply
Thread Tools Rate Thread

conditionally setting field values to 0

 
 
geert.van.ransbeeck@telenet.be
Guest
Posts: n/a
 
      3rd Feb 2009
Hello

I have this problem.

I made a query which amongst others contains a datafield
‘Enddate’ (with ex. 01/06/2011) and several other fields as ‘Y 2010’,
‘Y 2011’, ‘Y 2012’, ‘Y 2013’ … All those fields a filled in with data.

What I want to become: I finally want to create a report in which all
fields like ‘Y 2010’, ‘Y2011’ which depass the value of my field
‘Enddate’ are set to zero.

Ex. ‘Enddate’= 01/06/2011; in this case all values for this record in
the fields ‘Y2012’, ‘Y2013’, … must be set to zero. If 'Enddate' =
01/08/2012 all values for this record in the fields ‘Y2013’, ‘Y2014’,
‘Y2015’ … must be set to zero.

So it has to be checked record by record.

I am a beginner in vba. I suppose only vba is appropriate here.

Can anybody help me please?
Thank you.
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      3rd Feb 2009
No offense, but your table isn't normalized. Fields like Y2010, Y2011, Y2012
etc are referred to as a repeating group, and are a violation of database
normalization rules. Having them in your table makes your query far more
difficult than it should be!

That having been said, you can easily alter your query so that it returns 0
as appropriate. Rather than

SELECT Field1, Field2, Field3, Enddate,
Y2010, Y2011, Y2012, Y2013, Y2014, Y2015
FROM MyTable

use

SELECT Field1, Field2, Field3, Enddate,
IIf(Year(Enddate) < 2010, 0, MyTable.Y2010) AS Y2010,
IIf(Year(Enddate) < 2011, 0, MyTable.Y2011) AS Y2011,
IIf(Year(Enddate) < 2012, 0, MyTable.Y2012) AS Y2012,
IIf(Year(Enddate) < 2013, 0, MyTable.Y2013) AS Y2013,
IIf(Year(Enddate) < 2014, 0, MyTable.Y2012) AS Y2014,
IIf(Year(Enddate) < 2015, 0, MyTable.Y2013) AS Y2015
FROM MyTable

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


<(E-Mail Removed)> wrote in message
news:032aaffa-30e8-424f-985f-(E-Mail Removed)...
Hello

I have this problem.

I made a query which amongst others contains a datafield
‘Enddate’ (with ex. 01/06/2011) and several other fields as ‘Y 2010’,
‘Y 2011’, ‘Y 2012’, ‘Y 2013’ … All those fields a filled in with data.

What I want to become: I finally want to create a report in which all
fields like ‘Y 2010’, ‘Y2011’ which depass the value of my field
‘Enddate’ are set to zero.

Ex. ‘Enddate’= 01/06/2011; in this case all values for this record in
the fields ‘Y2012’, ‘Y2013’, … must be set to zero. If 'Enddate' =
01/08/2012 all values for this record in the fields ‘Y2013’, ‘Y2014’,
‘Y2015’ … must be set to zero.

So it has to be checked record by record.

I am a beginner in vba. I suppose only vba is appropriate here.

Can anybody help me please?
Thank you.


 
Reply With Quote
 
geert.van.ransbeeck@telenet.be
Guest
Posts: n/a
 
      3rd Feb 2009
Y2013, Y2013, etc are just example names I gave and (sorry) indeed not
normalised. In my reality they have other names (impact 2009, impact
2010 ....
So that's not the point.
 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      3rd Feb 2009
So did my suggestion solve your problem or not?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


<(E-Mail Removed)> wrote in message
news:b39d35a3-39a9-484d-9510-(E-Mail Removed)...
> Y2013, Y2013, etc are just example names I gave and (sorry) indeed not
> normalised. In my reality they have other names (impact 2009, impact
> 2010 ....
> So that's not the point.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
setting dynamic values to a field יניב מינקוב Microsoft Access Forms 2 25th Sep 2008 09:01 AM
Table fields:- Setting default values to be based on other field values Rob W Microsoft Access 3 20th Feb 2008 08:51 PM
Creating New Field and Conditionally Setting it's Value =?Utf-8?B?S2F0aGxlZW4=?= Microsoft Access Queries 3 16th Dec 2005 04:26 PM
Setting field values from expressions JC Microsoft Access Form Coding 3 2nd Jan 2004 06:04 PM
Setting Field values in a For Next Loop Chris B Microsoft Access Form Coding 5 17th Nov 2003 03:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:03 PM.