Results 1 to 5 of 5
  1. #1
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151

    Macro using 'date' (current system date)

    I have several if statements checking the dates entered against each other (there is a logical progression, where, for example, a record cannot be completed before it is received. Also, I check against the system date to make sure the user doesn't enter a future date.


    I use the following code on the before update event, and it works perfectly.
    Private Sub DateReceived_BeforeUpdate(Cancel As Integer)
    If DateReceived > Date Then
    MsgBox "Date Received cannot be in the future"
    Cancel = True
    End If
    End Sub

    But when I try to put the same logic in a macro to run prior to saving, I get an error message
    "Quality Review Database cannot find the name 'Date' you entered in the expression."



    Is there different syntax when referring to the system date within a macro?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Would have to review the macro settings. Are you use Date() in the macro?

    If you have functional VBA why change to macro? I don't use macros.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    cactuspete13 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    53

    Macro using 'date' (current system date)

    Try using "DateReceived > Date (Now())" That should tell it to check the date entered in the DateReceived block and compare it to the current date, instead of looking for a field labeled Date.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Date() and Now() are functions that don't have arguments. The nesting errors.

    I am testing calling system date in a macro. Trying to simply have MsgBox show it. It just treats the Date() function as a string. So I tested an If Then Else using Date() compared to a static value and have message box return True or False. That works.

    Include the ().

    VBA so much easier.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    Using the () was what I was missing. Thanks.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 01-22-2014, 03:45 PM
  2. Replies: 6
    Last Post: 12-11-2012, 09:40 PM
  3. Replies: 25
    Last Post: 11-16-2012, 12:47 PM
  4. Replies: 3
    Last Post: 10-25-2012, 10:04 PM
  5. Replies: 1
    Last Post: 12-07-2011, 01:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums