Results 1 to 2 of 2
  1. #1
    Dominic is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    1

    Angry switch statement in a access query

    Hello,
    i am trying to use a switch statement in a access query and i be leave i have the code right but for some reason it will only output a string i need it to output an long integer please look over my code and see if you have any ideas.(all the columns that are in the statement are Numbers)
    thank you

    Code:
    columnName:Switch (([column1]<>0), [column1], ([column2]<>0), [column2], ([column3]<>0), [column3],([column4]<>0),[column4],([column4]=0),0)

    outputs a string i need an
    long integer
    i have tried
    Code:
    columnName:Switch (([column1]<>0), CLng(column1), ([column2]<>0), CLng(column2), ([column3]<>0), CLng(column3),([column4]<>0),CLng(column4),([column4]=0),0)

    and dose not work just outputs a string
    It outputs the right number but not as an intiger
    anyone got any ideas
    thank you ahead of time

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try Val function:

    Val(Switch (([column1]<>0), [column1], ([column2]<>0), [column2], ([column3]<>0), [column3],([column4]<>0),[column4],([column4]=0),0))
    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.

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

Similar Threads

  1. Switch to Access 2010
    By NISMOJim in forum Access
    Replies: 1
    Last Post: 11-17-2012, 09:45 PM
  2. Switch Statement in WHERE Clause
    By Gray in forum Queries
    Replies: 1
    Last Post: 06-02-2011, 06:50 AM
  3. Using SQL switch function MS Access
    By sandlucky in forum Queries
    Replies: 18
    Last Post: 03-31-2011, 08:49 AM
  4. Case or Switch in an update statement
    By allenjasonbrown@gmail.com in forum Queries
    Replies: 7
    Last Post: 11-17-2010, 01:49 AM
  5. Replies: 6
    Last Post: 04-06-2010, 03:00 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