Robert L. Stewart
rl_stewart at highstream.net
Thu Oct 9 13:26:36 CDT 2003
Oleg, You need to rename your table. DATE is a reserved word in Access and you are probably hitting that as an issue. I would recommend naming it tsys_LastDate. You know it is a table (t). You know the system uses it (sys). And, you know it's function (Last Date). Also, I would name your command button something other than Command1. Something like this would work: Sub Check_Run_Date() dim db as database, rs as recordset set db = currentdb() set rs = db.openrecordset("SELECT * FROM tsys_LastDate;", dbopendynaset) if DateDiff("h", rs!LDate, now()) > 14 then rs.edit rs!LDate = now() rs.update Else msgbox ("The function was already performed today") End If rs.close set db = nothing End Sub At 11:45 AM 10/9/2003 -0500, you wrote: >Date: Thu, 9 Oct 2003 10:07:20 -0400 (EDT) >From: <Oleg_123 at xuppa.com> >Subject: Re: [AccessD] Help, date diff >To: <accessd at databaseadvisors.com> >Message-ID: <48692.12.3.132.98.1065708440.squirrel at heck.bay9.com> >Content-Type: text/plain; charset=iso-8859-1 > >Thanks Stuart, >this works goo, exsept I am still not able to update the table... >With this line commented, it works >DoCmd.RunSQL "Update Date Set ldate = Now()" > >Also, I'd like it to be performed on opening of the database. Is that >possible ? > > >Private Sub Command1_Click() > >last_time = DLookup("ldate", "Date") >nnow = Now() > >andy = DateDiff("h", last_time, nnow) > >If andy > 14 Then > DoCmd.SetWarnings False > ' DoCmd.RunSQL "Update Date Set ldate = Now()" > msgbox ("ok") > DoCmd.SetWarnings True >Else > msgbox ("The function was already performed today") >End If > >End Sub