Results 1 to 6 of 6
  1. #1
    sleake is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    51

    Code with If statement to check a check box has syntax error

    I am getting a syntax error for the following code. I want a check box checked if a record status is "In process" and today's date is greater than the date in the field [dteDate_Hard], indicating that the item is overdue.
    Code:
     Private Sub Form_Current()
    If([txtStatus]= "in Process" And Date() > [dteDate_Hard] Then
    [chkOverdue] = True
    Else
    [chkOverdue] = False
    End If
    End Sub
    Also, should I name the field/control Hard_Date to avoid conflict with the reserved name?

  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,929
    There is a solo parenthesis after the If and should be a space there.

    Why save this calculated result to table? Just calculate in ControlSource when needed.

    Not seeing a conflict with reserved word in that code but yes, avoid naming anything with reserved words.
    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
    sleake is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    51
    The check box is unbound. (The form is opened occasionally to display the status of records that are "In process," so no need to put it in a table.)

    I deleted my results and questions, as I'm find errors in naming. Have a meeting this morning, but will post back after the cleanup of names. I also will have questions about two DateDiff calculations in unbound controls.
    Last edited by sleake; 06-26-2014 at 05:03 AM. Reason: Found naming conventions inconsistencies needing cleanup

  4. #4
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    The syntax as shown IS incorrect. There is a , to much. If in VBA isn't like IIf:
    Code:
    If [txtStatus] = ”in Process” And Date() > [dteDate_Hard] Then
        [chkOverdue] = True
    Else
        [chkOverdue] = False
    End If
    And as June7 already stated you should use a calculated field in a query (no value to save to a table here) to get a field you can bind to the chkOverdue checkbox. Its faster and cleaner.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If the checkbox is unbound and code is used to set value, then all records will display the same value. Is the form in datasheet or continuous view? Better to use expression in ControlSource property.
    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.

  6. #6
    sleake is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    51
    Because of your suggestion, found my way to the Expression Builder, and this is now working as the Control Source: =IIf([txtStatus]="In process" And Date()>[Date_Hard],True,False)

    I'll do a separate post of my DateDiff questions.

    Thanks for guiding me to the answer.

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

Similar Threads

  1. Replies: 4
    Last Post: 02-03-2014, 12:16 PM
  2. Using Check boxes for an if statement
    By brow1726 in forum Forms
    Replies: 3
    Last Post: 06-10-2013, 09:50 PM
  3. Replies: 13
    Last Post: 04-17-2013, 04:17 PM
  4. IIF statement based on check box returns #error
    By timmygrover in forum Queries
    Replies: 7
    Last Post: 09-04-2012, 04:41 PM
  5. Duplicate Check code with Run-Time error '3079'
    By viper in forum Programming
    Replies: 5
    Last Post: 10-18-2010, 10:12 AM

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