Results 1 to 14 of 14
  1. #1
    Seeletse is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    11

    Unable to get Switch working correctly

    i'm running the below query as the control source for a level field. the result depending on the value in the marks field should set as the value for the level. Unfortunately I get the #Name? error.



    =Switch([Test_Score_Card]![Marks]>79,"7",[Test_Score_Card]![Marks]>69,"6",[Test_Score_Card]![Marks]>59,"5",[Test_Score_Card]![Marks]>49,"4",[Test_Score_Card]![Marks]>39,"3",[Test_Score_Card]![Marks]>29,"2",True,"1")

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    That isn't a query, it is an expression. Is Marks a field the form/report RecordSource? Why the prefix of table name? Is there more than one field in the RecordSource named Marks?
    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
    Seeletse is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    11
    Is Marks a field the form/report RecordSource - Yes
    Why the prefix of table name? - Thought that's how it's supposed to be
    Is there more than one field in the RecordSource named Marks - No

  4. #4
    Seeletse is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    11
    thanks, i just tried it and it works.

  5. #5
    Seeletse is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    11
    however, i went to the table that should hold the information from the form and the level field is empty.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    That won't save data to table. It is just a calculation. If you want to save the value will require code behind form. The trick is figuring out what event to put the code in. Maybe the AfterUpdate of Marks: Me!Level = Me.Leveltextbox

    Or just calculate whenever needed.
    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
    Seeletse is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    11
    There is a marks field in another table in the DB.

  8. #8
    Seeletse is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    11
    how can i get the level to updated when information is entered in the marks field? I tried putting the expression in AfterUpdate of Marks but that didn't work. Should i try it in the lost focus instead?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Why didn't it work, what happened - error message, wrong results, nothing? If it didn't work in AfterUpdate I doubt will work in LostFocus.
    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.

  10. #10
    Seeletse is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    11
    nothing is displayed.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Nothing is displayed in table after the code runs? No error message? Post the procedure for analysis or provide db. Follow instructions at bottom of my post.
    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.

  12. #12
    Seeletse is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    11

    database upload

    database upload done
    Attached Files Attached Files

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Code is behind the wrong control. My suggestion was to use the Marks AfterUpdate event.

    The Switch calculation does not go in event property. It can be be in ControlSource or in the VBA. The Switch syntax is wrong. See earlier post. Level is a number field so omit the quote marks.

    Event property would be [Event Procedure] for VBA code:
    Private Sub txtScoreCardMarks_AfterUpdate()
    Me!Level = Switch([Marks] > 79, 7, [Marks] > 69, 6, [Marks] > 59, 5, [Marks] > 49, 4, [Marks] > 39, 3, [Marks] > 29, 2, True, 1)
    End Sub

    Set the ControlSource of txtScoreCardLevel to Level. If you don't want users to edit this value then set properties Locked Yes and TabStop No.
    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.

  14. #14
    Seeletse is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    11
    thanks, it's now sorted.

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

Similar Threads

  1. Sort function not working correctly
    By kristyspdx in forum Reports
    Replies: 2
    Last Post: 10-09-2012, 11:04 AM
  2. Replies: 1
    Last Post: 10-25-2011, 09:47 PM
  3. Condtion not working correctly
    By hawkins in forum Access
    Replies: 3
    Last Post: 09-07-2011, 02:59 PM
  4. Split Form not working correctly
    By Brian62 in forum Access
    Replies: 29
    Last Post: 02-16-2010, 05:43 PM
  5. Search field is not working correctly
    By jakeao in forum Programming
    Replies: 9
    Last Post: 05-18-2009, 07:47 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