Changing date field color within query - Access/VBA

Hi Experts

I have following condition for which i would like to have fields highlited with colors when query results being viewed in Datasheet view.

1 = Red
2 = Yellow

IIf(([DATEDUE]<Date()),1,IIf([DATEDUE]>Date() And [DATEDUE]<DateAdd("d",+30,Date()),2))

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can't do that in a query datasheet.

You need to build a form from your query and you can then use Conditional Formatting  (from the format menu) for the field. The default view for your form can be set as datasheet in the form properties.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
driversAuthor Commented:

Thanks for suggestion, due to nature of this dynamic query its lot of overhead for me. It is actually being exported to excel and was hoping that formatting show up in excel too..

There is a suggestion somwhere to use field Format property within QBE using 0[Black];0[Red];0[Black], however trying to use with logic (two colors as stated above) but can't seems to figure out.

Any ideas?

The field formats represent     positives ; negatives; zero   so you can't use the feature to distinguish between positive values.

( Although if it could be used, then  the formatting would carry over to Excel on an export.)

I'm afraid I can't see a solution for you using the query datasheet.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

driversAuthor Commented:
well i guess i have to take that as last resort, but before i am wondering is it possible if i can call this from creating a function? if it is then can you give me high level example

some thing like this

if queries!testquery!Datedueflag = 1 then
   queries!testquery!Datedueflag.backcolor(or fontcolor) = vbred
   elseif ......

In a continuous form or datasheet , the only way to get different colours in different records is to use conditional formatting.

If you use code, then the colour that is appropriate to the current record is applied to all visible records.
driversAuthor Commented:
ok..thanks for your help anyway
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.