Results 1 to 13 of 13
  1. #1
    Gravy is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2017
    Posts
    6

    How to write Switch function in VBA - Help

    Am a self taught user and don't know VBA or SQL so have come up on a problem using the Switch functionality. It appears that Switch only allows 15 combinations and I have considerably more that I need,to put in.



    I've got this ( shortened version) and it's working well... but I can't add the remainder of the combinations:

    Risk: Switch([Consequence] = 1 AND [Likelihood] = 1, "Low",
    [Consequence] = 1 AND [Likelihood] = 2, "Medium")

    Can anyone tell me how I can fix this and please be very clear as I have absolutely no prior knowledge using VBA

    thanks in advance

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    I'd like to hear more about the number of consequences and likelihoods and what you'd want outcome to be?

  3. #3
    Gravy is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2017
    Posts
    6
    There are 20 possible variants for this particular item
    ive also got another similar piece with about 40 variants

    So if you pick

    Remote from Consequence field and
    Minor from Likelihood field
    Your risk rating will be Low (returned in third field)

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    I had no problem building Switch with 20 elements.

    However, you are probably hitting a limit for number of characters allowed in a single cell of query design grid, which is 1024.

    Options:

    1. a table of these risk combinations

    2. a custom VBA function
    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
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Maybe easier to create a table of consequence,likelihood,outcome Unless there's a mathematical link between your ones and zeros and the outcome word.

  6. #6
    Gravy is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2017
    Posts
    6
    Ahhh ok I did get too much text so may have to rename those dields
    i have a table,set,up with the three fields and all variations but I don't know how to use the existing data ...is it dlookup?

  7. #7
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Wondering if you could link the tables on the two fields you have

  8. #8
    Gravy is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2017
    Posts
    6
    I checked character count, it will only accept 756 with spaces...is there some way I can increase it to the 1024 you mentioned?

    the fields are in the one table
    I used Switch because I couldn't work out how to refer to that table and say if they pick this item and that item return the result picked from third field...I know it can be done I'm just not sure how ... Switch worked until I had too many possibilities ��

  9. #9
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Then dlookup probably easiest.

  10. #10
    Gravy is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2017
    Posts
    6
    Thanks
    better start googling how to do dlookup

  11. #11
    Gravy is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2017
    Posts
    6
    So does dlookup capture the result against a record or only shows the result in the form?

  12. #12
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Captures result from a table based on a form or other value

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Domain aggregate functions can be slow performers in query and textbox so a table join is preferable if at all possible. So if you have every possible combination of the 3 values in table, should be able to join on the Consequence and Likelihood fields (compound link) and that will make the Rating field available.

    Domain aggregate functions can be used in query, textbox, VBA.

    I don't know why your expression fails at 756 characters, should allow 1024. There is no way to modify Access specification limits. http://www.databasedev.co.uk/access_specifications.html
    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. Alernative to SWITCH function???
    By elender in forum Queries
    Replies: 5
    Last Post: 02-09-2017, 06:54 PM
  2. Replies: 3
    Last Post: 05-06-2011, 02:49 PM
  3. count and switch function in same select query
    By sandlucky in forum Queries
    Replies: 2
    Last Post: 04-08-2011, 11:16 PM
  4. Using SQL switch function MS Access
    By sandlucky in forum Queries
    Replies: 18
    Last Post: 03-31-2011, 08:49 AM
  5. Select Query in Switch Function
    By sandlucky in forum Queries
    Replies: 0
    Last Post: 03-30-2011, 04:54 AM

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