Macro to compare Date in form to Date in table

Sketchin

Registered User.
Local time
Yesterday, 17:56
Joined
Dec 20, 2011
Messages
577
I would like to create a macro that will compare "Date Out Requested" entered in a control on frmReservations to DateOut and DateIn in tblReservations.

Can I do this in a macro so that it automatically checks if there is an overlapping reservation? I can do it with a query, but the no-it-all bosses want it done automagically in the background.

This is the macro I have set up that isnt working:

If [Forms]![frmReservations]![DateOutReq] Between [tblReservations]![DateOut] And [tblReservations]![DateIn] then

It gives me an error:
"You may have specified a control that wasn't on the current object without specifying the correct form or report context"

Is the problem that you can't compare form data to data that is already existing in a table?

Thanks!
 
Sure, but you can't refer to the table that way. Since you say you can do it in a query, you can use DLookup or DCount on your query, or open a recordset on it. That way you're still doing your process in the background.

If appropriate to your structure, this may help with the query:

http://www.baldyweb.com/OverLap.htm
 

Users who are viewing this thread

Back
Top Bottom