Calculating dates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to write some code that takes a date from a table and compare it
to a date entered on a form. I want to display a warning form if the table
date is earlier than the date on the form. Below is the code that I have
written, but it does not seem to be working. I am not getting an error
message, but the code is also not working. Any help would be great.

If DateDiff("d", Me.pdName.Column(5), Forms.ach_entry_form.Revenue_Date) < 0
Then
DoCmd.OpenForm Forms.change_warning_form
Else
Me!Description.SetFocus
 
For one thing, using "Me.xxxx" tells Access to look at an object contained
inside the form (or report) in which the code is running. I don't believe
your "table" lives inside your form.

For another, I don't recall seeing a way to use DateDiff() against a table,
and, if I understand what you are trying to do, a specific column in that
table. How would you compare a specific field in a table, across all rows
of the table, with a single date entered in a form's control?

How are you getting "a date from a table"? Where is that happening?

More info, please...

Jeff Boyce
<Office/Access MVP>
 
Jeff,

Thanks for the reply, I am using a combo box (pdname) on a subform of the
main form (where the Revenue date field is). The Combo box allows you to
pick the individual that you want and the rowsource for this selection is
based on a table, which contains the date I am looking for. In the selection
query I have included the dates in column 5 of my selection query for the
combo box. Sorry for the confusion on this question.

If the datediff() function won't work, please give me some ideas to use
instead. Thanks agian.
 
Given the description, the DateDiff() function will work.

However, if the combo box is on a subform, you'll need to refer to the
subform, not (only) the main form. Check Access HELP re: expressions, to
get an idea of syntax for that.

Regards

Jeff Boyce
<Office/Access MVP>
 
Back
Top