473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Formating negative numbers

20
Need someones help for what I believe is a simple process, but something I am doing is wrong. I am working in Access 2003 program in a simple Jet query. What I am trying to do is subtract two dates and have the negative number have parenthese around it as well as turn the color red. According to what I have tried to figure out on my own the sting should go something like this; Format([PromissDate]-[CompletionDate],(0) [Red]). But it doesn't seem to work. What am I missing here?

Thanks for your help
Aug 15 '07 #1
6 5590
Scott Price
1,384 Expert 1GB
Need someones help for what I believe is a simple process, but something I am doing is wrong. I am working in Access 2003 program in a simple Jet query. What I am trying to do is subtract two dates and have the negative number have parenthese around it as well as turn the color red. According to what I have tried to figure out on my own the sting should go something like this; Format([PromissDate]-[CompletionDate],(0) [Red]). But it doesn't seem to work. What am I missing here?

Thanks for your help
Not sure about doing this in a query, but in vba it would be fairly simple.

An overview:
You would use the DateDiff() function to calculate the difference between the two dates, then place an If... Then structure to determine if the promise date is > (greater than) the completion date. Then change the color to red using the .forecolor property of the control, and concatenate the parentheses around the resulting value from the DateDiff() function.

Please ask if you have any questions about this process!

Regards, and welcome to the Scripts!
Scott
Aug 15 '07 #2
Scott Price
1,384 Expert 1GB
Here's a quick and dirty solution I just cooked up :-) Place it in the AfterUpdate event of your txtbox that accepts the Completion date...
Expand|Select|Wrap|Line Numbers
  1. Dim PromiseDate as Date
  2. Dim CompleteDate as Date
  3. Dim Differ as Integer
  4. Dim lngRed as Long
  5.  
  6. lngRed = RGB(255, 0, 0)
  7. PromiseDate = Me.txtPromiseDate
  8. CompleteDate = Me.txtCompleteDate
  9. Differ = DateDiff("d", PromiseDate, CompleteDate)
  10.  
  11. If PromiseDate > CompleteDate Then
  12.     Me.txtDiffer.ForeColor = lngRed
  13.     Me.txtDiffer = "(" & Differ & ")"
  14.     MsgBox "You blew it! Project overdue!!", , "Overdue!"
  15. Else
  16.     Me.txtDiffer = Differ
  17.     MsgBox "Good job! You finished on time and below budget!  Bonuses all around!"       
  18. End If
Regards,
Scott
Aug 15 '07 #3
FishVal
2,653 Expert 2GB
Need someones help for what I believe is a simple process, but something I am doing is wrong. I am working in Access 2003 program in a simple Jet query. What I am trying to do is subtract two dates and have the negative number have parenthese around it as well as turn the color red. According to what I have tried to figure out on my own the sting should go something like this; Format([PromissDate]-[CompletionDate],(0) [Red]). But it doesn't seem to work. What am I missing here?

Thanks for your help
Hi, Steve.

I completely agree with Scott in all points but one - concerning programmatic change of TextBox.Forecolor. This will work on single form view only. In datasheet and continious form view Scott's code will change the field color in all rows/forms. So conditional formatting will be a better solution here.

I suggest the following:

Build a query
Expand|Select|Wrap|Line Numbers
  1. SELECT tbl.*, DateDiff("d",tbl.dteCompletionDate,tbl.dtePromissDate) AS lngDateDiff, Switch(lngDateDiff<0,"(" & lngDateDiff & ")",lngDateDiff>=0,lngDateDiff) AS txtOutput
  2. FROM tbl;
  3.  
Create a form based on the query (BTW the simplest way to do it is to use [AutoForm] button).

Apply conditional formatting on the control corresponding to txtOutput field of the query.
Set Condition1 to
[Field value is] - [less than] - ["0"]
Don't miss double quotes as ControlSource is text type.

Good luck.
Aug 15 '07 #4
Scott Price
1,384 Expert 1GB
FishVal is right on my code changing the color for all records in continuous form view!

I had forgotten that in the situation I pulled this code from, that in my subform continuous form view I used conditional formatting, but in my single form - detail view (accessed via a Detail command button on my subform) I used a very similar version of the code I posted above.

Anyway, go with what works for your situation! And post back here if you have any questions.

Regards,
Scott
Aug 15 '07 #5
Steve67
20
Thanks guys for all your help. The information was very useful. I ended up going a different route and changed the script to an If statement, then changed the conditional formate in the Report section and everything came out to what I needed to accomplish. Once again, thanks for your input.

Steve
Aug 15 '07 #6
Scott Price
1,384 Expert 1GB
Thanks guys for all your help. The information was very useful. I ended up going a different route and changed the script to an If statement, then changed the conditional formate in the Report section and everything came out to what I needed to accomplish. Once again, thanks for your input.

Steve
Glad we could help!

Regards,
Scott
Aug 15 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: pj | last post by:
Why does M$ Query Analyzer display all numbers as positive, no matter whether they are truly positive or negative ? I am having to cast each column to varchar to find out if there are any...
5
by: Subrahmanyam Arya | last post by:
Hi Folks , I am trying to solve the problem of reading the numbers correctly from a serial line into an intel pentium processor machine . I am reading 1 byte and 2byte data both positive...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
11
by: drtimhill | last post by:
I'm just starting out on Python, and am stumped by what appears an oddity in the way negative indices are handled. For example, to get the last character in a string, I can enter "x". To get the...
39
by: Frederick Gotham | last post by:
I have a general idea about how negative number systems work, but I'd appreciate some clarification if anyone would be willing to help me. Let's assume we're working with an 8-Bit signed integer,...
3
by: Steven D'Aprano | last post by:
Problem: I have an application where I need to print integers differently depending on whether they are positive or negative. To be more specific, I have to print something that looks like: ...
4
by: eriwik | last post by:
I'm trying to write floats to a file following a specific format (8 characters/record, and some other rules) and seem to have solved all but one problem. There is no way of telling the maximum...
20
by: Casey | last post by:
Is there an easy way to use getopt and still allow negative numbers as args? I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.