Help with textbox & date please
Author |
Message |
Dave #1 / 6
|
 Help with textbox & date please
Hi, Ive created a mini database for a client, one of the textboxes is the 'payment date' - i want the text in this to turn red if it is ealier than the system date, the method I used below only seems to work with the first 2 numbers of the date. i.e it makes 27/12/2002 red even though today is 28/11/2002 (i assume it's only reading the 'DD' or the days date) the code i used is as follows: If txtPayment.text < Date Then txtPayment.Forecolor = &HFF& Else txtPayment.Forecolor = &H80000008& End if how can i modify this code so it only turns red at an earlier date than is displayed - date format is e.g 28/11/2002? Thanks in advance of any help in this as Ive tried numerous combinations but none seem to work Dave
|
Tue, 17 May 2005 01:35:30 GMT |
|
 |
Frank Ad #2 / 6
|
 Help with textbox & date please
Quote:
>Hi, >Ive created a mini database for a client, one of the textboxes is the >'payment date' - i want the text in this to turn red if it is ealier than >the system date, the method I used below only seems to work with the first 2 >numbers of the date. i.e it makes 27/12/2002 red even though today is >28/11/2002 (i assume it's only reading the 'DD' or the days date) the code i >used is as follows: >If txtPayment.text < Date Then >txtPayment.Forecolor = &HFF& >Else >txtPayment.Forecolor = &H80000008& >End if >how can i modify this code so it only turns red at an earlier date than is >displayed - date format is e.g 28/11/2002?
If Not IsDate(txtPayment.Text) Then Exit Sub 'don't forget txtPayment.ForeColor = IIf(DateDiff("d", txtPayment.Text, Date) > 0, _ vbRed, vbBlack) ' use constants for simple colors. -- Regards, Frank
|
Tue, 17 May 2005 06:38:57 GMT |
|
 |
Harry Strybo #3 / 6
|
 Help with textbox & date please
Quote: > Hi, > Ive created a mini database for a client, one of the textboxes is the > 'payment date' - i want the text in this to turn red if it is ealier than > the system date, the method I used below only seems to work with the first 2 > numbers of the date. i.e it makes 27/12/2002 red even though today is > 28/11/2002 (i assume it's only reading the 'DD' or the days date) the code i > used is as follows: > If txtPayment.text < Date Then > txtPayment.Forecolor = &HFF& > Else > txtPayment.Forecolor = &H80000008& > End if > how can i modify this code so it only turns red at an earlier date than is > displayed - date format is e.g 28/11/2002? > Thanks in advance of any help in this as Ive tried numerous combinations but > none seem to work > Dave
The expression "If txtPayment.text < Date Then" is a bit like comparing apples and oranges which are both fruit but not the same. To compare dates, you need to compare date data types: Either use the DateDiff function or "If CDate(txtPayment.text) < Date Then"
|
Tue, 17 May 2005 06:49:51 GMT |
|
 |
Frank Ad #4 / 6
|
 Help with textbox & date please
On Thu, 28 Nov 2002 22:49:51 GMT, "Harry Strybos" Quote:
>> Hi, >> Ive created a mini database for a client, one of the textboxes is the >> 'payment date' - i want the text in this to turn red if it is ealier than >> the system date, the method I used below only seems to work with the first >2 >> numbers of the date. i.e it makes 27/12/2002 red even though today is >> 28/11/2002 (i assume it's only reading the 'DD' or the days date) the code >i >> used is as follows: >> If txtPayment.text < Date Then >> txtPayment.Forecolor = &HFF& >> Else >> txtPayment.Forecolor = &H80000008& >> End if >> how can i modify this code so it only turns red at an earlier date than is >> displayed - date format is e.g 28/11/2002? >> Thanks in advance of any help in this as Ive tried numerous combinations >but >> none seem to work >> Dave >The expression "If txtPayment.text < Date Then" is a bit like comparing >apples and oranges which are both fruit but not the same. To compare dates, >you need to compare date data types:
{*filter*}y hell. I was a bit suspicious when the greengrocer (Jon) told me that these were Jonathan oranges. ;-) -- Regards, Frank
|
Tue, 17 May 2005 07:18:33 GMT |
|
 |
J Fren #5 / 6
|
 Help with textbox & date please
I see that you are using UK/European Date format How are you validating the input of the date ? Dim D As Date actually declared D as a Double Precision number DateSerial is probably the safest way of interpreting a 'text date' and converting it into a Date type number. In a : dd/mm/yyyy locale try this :- Private Sub Command1_Click() Dim D As Date D = CDate("1-13-2002") Me.Print D End Sub VB is far too clever for its own good. Quote:
>Hi, >Ive created a mini database for a client, one of the textboxes is the >'payment date' - i want the text in this to turn red if it is ealier than >the system date, the method I used below only seems to work with the first 2 >numbers of the date. i.e it makes 27/12/2002 red even though today is >28/11/2002 (i assume it's only reading the 'DD' or the days date) the code i >used is as follows: >If txtPayment.text < Date Then >txtPayment.Forecolor = &HFF& >Else >txtPayment.Forecolor = &H80000008& >End if >how can i modify this code so it only turns red at an earlier date than is >displayed - date format is e.g 28/11/2002? >Thanks in advance of any help in this as Ive tried numerous combinations but >none seem to work >Dave
|
Tue, 17 May 2005 15:43:40 GMT |
|
 |
Paul Hickma #6 / 6
|
 Help with textbox & date please
Because of the tendency of Microsoft product to default unexpectedly to US date formats once you start to process them, I always pass my dates through a function that converts them to yyyymmdd format. They then (1) get stored in database correctly and (2) are correctly compared with other dates. Here is the function: Public Function FormatDate(sDate As String) as Long If IsDate(sDate) Then 'converts to yyyymmdd date FormatDate = CLng(Right(sDate, 4) & Mid(sDate, 4, 2) & Left(sDate, 2)) 'or you can do the first element of the date as Right(sDate, 2) if you want to use dd/mm/yy Else MsgBox "Incorrect date entered.", vbOKOnly, "Data entry error" End If End Function Your If statement would then be: If FormatDate(txtPayment.Text) < FormatDate(CStr(Date)) then ...
Quote: > Hi, > Ive created a mini database for a client, one of the textboxes is the > 'payment date' - i want the text in this to turn red if it is ealier than > the system date, the method I used below only seems to work with the first 2 > numbers of the date. i.e it makes 27/12/2002 red even though today is > 28/11/2002 (i assume it's only reading the 'DD' or the days date) the code i > used is as follows: > If txtPayment.text < Date Then > txtPayment.Forecolor = &HFF& > Else > txtPayment.Forecolor = &H80000008& > End if > how can i modify this code so it only turns red at an earlier date than is > displayed - date format is e.g 28/11/2002? > Thanks in advance of any help in this as Ive tried numerous combinations but > none seem to work > Dave
|
Thu, 19 May 2005 03:45:31 GMT |
|
|
1. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,
2. Please Help Date & Time Record Access
3. Simple Date & Time Help Please
4. dates & times HeLp please
5. Please, Please, Please I need help working with dates
6. *&*&*&* Date math question *&*&*&*
7. textbox & Date Null problem
8. Date - Date/time comparison - please help
9. Please, Oh Please Help Find first date plus
10. Can anyone HELP me PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE
11. Dates, Dates, & More Dates
12. Userform: populate textbox with date from another textbox
|
|
|