How to Set Field to Equal Now()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bullfrog83
    New Member
    • Apr 2010
    • 124

    #1

    How to Set Field to Equal Now()

    I have the following line of code in a sub in which I want to set a date/time field to equal the current date/time when a particular sub is executed:

    Code:
    CurrentDb.Execute "UPDATE StdDegReq SET LastEvaluted = Now() WHERE StdDegReqId = " & lngStdDegReqId
    I cannot get this to work. I've tried the following, each giving me either a syntax or too few parameters error:

    LastEvaluated = Now
    LastEvaluated = " & Now() & " WHERE...
    LastEvaluated = #" & Now() & "# WHERE...
    LastEvaluated = #" & Now & "# WHERE...

    I thought this would be simple! How do I write this?
  • gershwyn
    New Member
    • Feb 2010
    • 122

    #2
    The code you posted has a typo: LastEvaluted instead of LastEvaluated. If that's how it is in your code, that's certainly the problem.

    If that was just a mistake while posting your code, I would try assigning your SQL to a string variable, and use either the msgbox function or debug.print to see how it looks immediately before executing.

    Comment

    • bullfrog83
      New Member
      • Apr 2010
      • 124

      #3
      Originally posted by gershwyn
      The code you posted has a typo: LastEvaluted instead of LastEvaluated. If that's how it is in your code, that's certainly the problem.

      If that was just a mistake while posting your code, I would try assigning your SQL to a string variable, and use either the msgbox function or debug.print to see how it looks immediately before executing.
      Sadly, it was a typo! I should have figured that since I kept typing evaluated wrong (forgetting the "a") when giving the different examples of what I tried in my post.

      Comment

      • gershwyn
        New Member
        • Feb 2010
        • 122

        #4
        I do the same thing all the time - in fact, I assumed I had made the typo myself when I went to test your SQL. Glad it was an easy fix for you.

        Comment

        • OldBirdman
          Contributor
          • Mar 2007
          • 675

          #5
          If the project has the option "Require Variable Declaration" set, then each module will have "Options Explicit". This means that Access will require a declaration of the variable.
          I note that you use "Camel" names (mix of upper and lower case). When typing code, if you always type lower case, Access will correct to the declared form on completion of the statement. It is easy to see if you have a typo.
          If you fail to note that the name was not modified, Access raises an error if the statement is executed.
          I haven't seen any reason not to do this.

          Comment

          Working...