Results 1 to 9 of 9
  1. #1
    dcorleto is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    10

    macrohelp needed - error message if statement


    Can anyone please advise why the following would give this error message?

    Click image for larger version. 

Name:	Screen Shot 2013-07-21 at 1.03.00 PM.png 
Views:	12 
Size:	43.8 KB 
ID:	13144

  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,815
    What is [Today]![isdate] - a form and field names?

    Do what the error message instructs, try preceding the names with the collection reference:
    Forms![Today]![isdate]

    or just:
    [isdate]
    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
    dcorleto is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    10
    tried that...not using a form - I want the macro to check against a field in a table, is that possible

  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,815
    Would have to use expression with DLookup() domain aggregate function. Or maybe an sql SELECT statement, I think macros in 2010 can run sql statements, or maybe that is in data macros specifically. I don't use macros so not sure about the sql SELECT.
    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
    dcorleto is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    10
    thanks june7..I'm baffled why basic requests in access are still shrouded in code in 2013..I thought it would be as easy as to say...
    If in table x, the date is y, then
    don't execute this part of the macro...

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    That's what domain aggregate functions are for. They communicate instructions to Access. With DLookup the instruction is: look in table x and retrieve value from field y of first record that meets criteria.

    If the table Today were included in the form's RecordSource then its fields would be available for direct reference by the macro, assuming this is an embedded macro behind the form.
    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.

  7. #7
    dcorleto is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    10
    thank you Jun7. This is not a form though, just a macro of commands to open and run queries in order. I would like to run one of the queries only if a field in one of the tables of the db does not contain today's date. In other words, I am trying to find a logical way to run a query only once a day automatically by a macro.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Then use the DLookup to search table for the value.

    If IsNull(DLookup("isdate", "Today", "isdate=#" & Date() & "#")) Then
    'run code
    Else
    'do this
    End If
    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.

  9. #9
    dcorleto is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    10
    Wow, I think I am getting closer thanks to you!!! No more error message, the macro seems to be running, I just need to figure out if I have my logic right. I'll keep you posted.

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

Similar Threads

  1. Replies: 2
    Last Post: 04-04-2013, 03:13 PM
  2. If Statement Criteria Needed for form
    By burrina in forum Forms
    Replies: 4
    Last Post: 12-06-2012, 10:47 PM
  3. Replies: 4
    Last Post: 11-19-2012, 01:59 PM
  4. If Statement Criteria Needed for form
    By burrina in forum Forms
    Replies: 6
    Last Post: 11-16-2012, 11:00 PM
  5. Replies: 11
    Last Post: 03-21-2012, 12:51 PM

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