Results 1 to 3 of 3
  1. #1
    bogzla is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    2

    Switch with custom functions giving #ERROR

    The following query is giving me issues:



    Code:
    SELECT
    Switch([A.SalesNotes] like '*[C-D][0-9][0-9][0-9]*',mid([A.SalesNotes],FindIt([A.SalesNotes],'[C-D][0-9][0-9][0-9]'),4),[A.SalesNotes] like '*[C-D][0-9][0-9]*',mid([A.SalesNotes],FindIt([A.SalesNotes],'[C-D][0-9][0-9]'),3)) as 'Master Batch', A.WorksOrderNumber + '/A1' as WorksOrderNo
    FROM         Production_WorksOrder AS A
    WHERE     (A.SalesNotes LIKE '*[C-D][0-9][0-9][0-9]*' OR A.SalesNotes LIKE '*[C-D][0-9][0-9]*')
    ORDER BY 'Master Batch' DESC, A.WorksOrderNumber DESC
    I'm looking for and showing codes like C01, C012, D01, D012 which have a variable position with the SalesNotes field
    FindIt is a custom function that returns the position using regexp.
    In the above case C012 and D012 style codes are displayed fine but everything else shows #ERROR

    interestingly, if I strip it down to the following:
    Code:
    SELECT
    Switch([A.SalesNotes] like '*[C-D][0-9][0-9][0-9]*',FindIt([A.SalesNotes],'[C-D][0-9][0-9][0-9]'),[A.SalesNotes] like '*[C-D][0-9][0-9]*',FindIt([A.SalesNotes],'[C-D][0-9][0-9]')) as 'Master Batch', A.WorksOrderNumber + '/A1' as WorksOrderNo
    FROM         Production_WorksOrder AS A
    WHERE     (A.SalesNotes LIKE '*[C-D][0-9][0-9][0-9]*' OR A.SalesNotes LIKE '*[C-D][0-9][0-9]*')
    ORDER BY 'Master Batch' DESC, A.WorksOrderNumber DESC
    Then all positions returned by FindIt for all cases are displayed fine. This leads me to think there is something up in the way switch and mid are behaving but I cannot fathom what is going on...

    any help gratefully recieved!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Instead of using switches,
    use a lookup table joined to your table to convert, or a custom function.

  3. #3
    bogzla is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    2
    You know it never occured to me to put the whole thing in a function. Probably a bit blinkered as converting it from a SQL server CASE query.

    I would still be interested to understand what caused the error if anyone has some insight?

    cheers!

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

Similar Threads

  1. Control source Expression giving #Error
    By N3w2access in forum Forms
    Replies: 5
    Last Post: 01-21-2014, 07:53 AM
  2. Form with VBA code giving Error
    By tgwacker in forum Access
    Replies: 1
    Last Post: 12-03-2013, 10:14 PM
  3. DCount on a Query giving #Name? error
    By Huddle in forum Access
    Replies: 9
    Last Post: 06-20-2012, 11:40 AM
  4. Custom Functions
    By TheDeceived in forum Access
    Replies: 3
    Last Post: 09-16-2010, 02:12 PM
  5. NoData() still giving me an error.
    By cowboy in forum Programming
    Replies: 3
    Last Post: 04-08-2010, 12:26 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