Date Validation from related table

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

Guest

I'm trying to figure out how to validate a Due Date in one Table to Start and
End Dates in a related table. The Due Date need to fall within the correct
range, but I'm not sure how to write the code that links it to the other
table. Can someone help?
 
Jane,

If you have any code written, would you post it?

Are you wanting to validate Due Date in Table1 is between RelatedTable Start
Date and End Date by stepping thru Table1 or validate a control on a form
after entry?

There must be a linking field for the two tables, so you could open a record
set to get the start and end dates or use DLookup() to get the start and end
dates. Once you have the start and end dates, you could do:

'
'---snip--- (air code!!)
SDate = DLookup (...)
EDate = DLookup(...)

DDate = rs1.[Due Date]
' or
'DDate = Me.[Due Date]

If Not DDate Between SDate and EDate then
'notify due date not in range
' or change date to be in range, or ...
End If
'---snip---

If you didn't want to use DLookup(), you could open a recordset:
'------snip
Set rst = CurentDb.OpenRecordset("Select StartDate, EndDate From
RelatedTable Where RelatedTable.someField = Table1.SomeField;")

SDate = rst.StartDate
EDate = rst.EndDate
' use the If() function above
'---snip

Soooo, where is due date (table or Forms!FormName.ControlName), what is the
link field (to know how to find the correct date range), how to start
validation (exit the control, before form update, button event) and do you
have any code already?

HTH
Steve
 
Back
Top