Results 1 to 6 of 6
  1. #1
    euphonium01 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    40

    Macro If statement syntax error

    I am trying to create a Macro attached to the 'On Current' property of a Form. I need the Macro to change the BackColor of a control (called [Status]), base on the percentage of another control (called [Sales Potential]), the percentages are 0 to 10, 11 to 20 etc up to 100 % using a different color for each. I tried the following:



    If [Sales Potential] >=0 And <=10
    SetProperty
    Control [Sales Potential]
    Property BackColor
    Value #000000

    [Sales Potential] >=11 And <=20 and so on.

    The above returns "syntax error, Cannot Parse the Expression >=0 And <=10", when I try to save.

    I also tried [Sales Potential] Between 0 And 10. SetProperty etc This saved but didn't work when I tried it.

    I've tried Else If statements, Else Statements for other percentage increments, but cannot get anything to work.

    I know the answer will be easy to someone, can anyone help a novice resolve this, I would be most appreciative.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Have you looked at Conditional Formatting on the ribbon? It's the simplest way to do this type of thing.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mrojas is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2013
    Location
    Concord California
    Posts
    72
    Try the following:

    If [Sales Potential] >=0 And [Sales Potential]<=10

  4. #4
    euphonium01 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    40
    Quote Originally Posted by pbaldy View Post
    Have you looked at Conditional Formatting on the ribbon? It's the simplest way to do this type of thing.
    Yes, I tried that, it worked for anything from 0 To 10, and from 11 To 20, after that (21 To 50 or 51 To 75 etc) wouldn't work?

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Note: If the numbers are really percents, you will need to use percent signs or decimals in your equations, i.e. 10% or .10.
    Percentages are equivalent to fractions/decimals between 0 and 1.

  6. #6
    euphonium01 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    40
    Many thanks to both mrojas and JoeM. Not sure which was right (as it's now working I don't wish to change anything to check it out). I used mrojas' suggestion of using the control name for both set of criteria, and also used JoeM's correction to change the numbers to a decimal (0 became 0.0 and 10 became 0.1 etc).

    Thanks to all who sent their help

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

Similar Threads

  1. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  2. Statement Syntax Error
    By Alex O in forum Access
    Replies: 8
    Last Post: 06-08-2012, 08:12 AM
  3. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  4. IIf Statement Syntax Error
    By shexe in forum Queries
    Replies: 2
    Last Post: 10-06-2010, 08:35 AM
  5. Syntax Error In Insert Into Statement
    By frankvfox in forum Queries
    Replies: 1
    Last Post: 09-09-2008, 12:35 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