Date Field Comparison?

  • Thread starter Thread starter Todd D. Levy
  • Start date Start date
T

Todd D. Levy

I have a report that grabs 2 date fields from different tables.

Date B can be the same as or later than Date A, but never before Date A.

Is there any way I can modify the report or perhaps the underlying query
to give the user a warning on a per record basis if Date B is earlier
than Date A?
 
If you just want a message box warning you can
code the Report's Detail Format event:

If [DateB] < [DateA] Then
MsgBox "There is a date problem with record " & [RecordID]
End if

[RecordID] is whatever field is the records unique Prime key
so that you can identify which record has the incorrect date problem.

You could just as easily change the color or whatever in a control to alert
the user.
If [DateB] < [DateA] Then
[SomeControl].BackColor = vbRed
Else
[SomeControl].BackColor = vbWhite
End if

Make sure the BackStyle property is Normal.
 
-----Original Message-----
(e-mail address removed) says...

This should do nicely; Thanks again Fred!
If you just want a message box warning you can
code the Report's Detail Format event:

If [DateB] < [DateA] Then
MsgBox "There is a date problem with record " & [RecordID]
End if

[RecordID] is whatever field is the records unique Prime key
so that you can identify which record has the incorrect date problem.

You could just as easily change the color or whatever in a control to alert
the user.
If [DateB] < [DateA] Then
[SomeControl].BackColor = vbRed
Else
[SomeControl].BackColor = vbWhite
End if

Make sure the BackStyle property is Normal.

--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.
.
Conditional formatting works VERY nicely for this, and
why it is available, I'm sure!

In design view, single click on the control(s)you want to
conditionally format.

Then select Format, then Conditional Formatting from your
main menu bar. Then select Expression Is from the list
box under Condition 1.

Type in the condition you want to satisfy before the
conditional formatting is applied to the control(s). For
instance:

[DateB] < [DateA].

If the chosen condition is true, then any conditional
format you select for the controls)will be applied instead
of the default format you've previously defined for the
control(s), ie bolded, colored, underlined, or italicized.

The only hitch is that if you are trying to conditionally
format multiple controls for a given record, you must
apply the formatting to each type of control group for
given record. In other words, you first conditionally
format all the text box controls for a record, then all
the combo boxes, etc. A little hassle there, but nothing
major. Certainly easier than writing If/Then VB code for
each control you want changed!

Hope this gives you another idea, and you can use
conditional formatting in others ways, too. for instance,
in a form, you may want to show the background of the "Got
Focus" control in an alternative color in order to
literally highlight it as the control with the focus.
Rather than coding its Got Focus and Lost Focus Event
Procedures (and coding all of the other controls, too!)
just use conditonal formating on all of them as a group!

Again, hope this is useful.
 
Marty,

Thanks, I had not heard of this.

Todd

why it is available, I'm sure!

In design view, single click on the control(s)you want to
conditionally format.

Then select Format, then Conditional Formatting from your
main menu bar. Then select Expression Is from the list
box under Condition 1.

Type in the condition you want to satisfy before the
conditional formatting is applied to the control(s). For
 
Back
Top