Results 1 to 5 of 5
  1. #1
    WallyZ is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    18

    String Functions in Query not compiling???

    I have a simple table that contains numeric values in a text column (TaskNo).

    tblTasks
    ID Auto Number
    TaskYear Date
    TaskNo ShortText (10)
    other fields ....

    I would like to sort the table by TaskNo numerically and found this on the net - Expr1:IIF([FIELD] IS NULL, 0, VAL([FIELD]))
    So I wrote this in the SQL view of my query

    SELECT tblTasks.[TaskYear], tblTasks.[TaskNo], IIF(tblTasks.[TaskNo] IS NULL, 0, VAL(tblTasks.[TaskNo])) AS NumericTaskNo FROM tblTasks

    I've left off the ORDER BY clauses for now as it doesn't change my issue.

    When I change to design view I see the Expr has been correctly formed in the field.

    But when I change to Data Sheet view I get the error:

    Compile error in query expression: 'IIF(tblTasks.[TaskNo] IS NULL, 0, VAL(tblTasks.[TaskNo])' <-- notice it always leaves off the last character



    The 'VAL' is highlighted. This occurs also with other functions such as MID, LEFT, RIGHT, etc.

    I checked my references and they are all good (none missing, VBA is there, MS Access 15 Object Lib is there) and I can use all these functions without issue from the Access VB editor.

    Also I cannot enter any function directly into the expression field while in design mode as it immediately complains it doesn't known about that function.

    What am I missing?

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    sql evaluates the entire expression, so I suspect it is failing on trying to evaluate a null value for the val function

    try changing

    'IIF(tblTasks.[TaskNo] IS NULL, 0, VAL(tblTasks.[TaskNo])'

    to

    val(nz(tblTasks.[TaskNo],0))

    or perhaps

    val(nz(tblTasks.[TaskNo],"0"))

  3. #3
    WallyZ is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    18
    Ajax suggested:

    val(nz(tblTasks.[TaskNo],0))

    or perhaps

    val(nz(tblTasks.[TaskNo],"0"))

    Query designer complained about both the VAL and NZ functions.

    I also tried these:

    Expr1: VAL(tblTasks.[TaskNo])

    Expr1: NZ(tblTasks.[TaskNo], "0")

    But query designer didn't like either.

    I believe the query designer is not seeing all the references provided in Tools->References! Why? Don't know!!!

    This worked:

    Expr1: IIF(
    tblTasks.[TaskNo], "0", "0")

    Not that it does anything but it shows it can resolve the IIF function.

    IIF is part of VBA.Interaction while all the other string functions are part of VBA.Conversion.

    So the designer is not happy about all the VBA functions!!!

  4. #4
    WallyZ is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    18

    More Info Access 2010 OK but 2013 Not OK

    More Info

    I tried all the previous expressions on a system with Access 2010 and they all worked no problem.

    The problem occurs only on my Access 2013 system!

  5. #5
    WallyZ is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    18
    This newby managed to figure it out.

    The problem was created by me failing to compile the VBA code completely. A duplicate function name prevented the Designer from recognizing the VAL function!

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

Similar Threads

  1. Replies: 3
    Last Post: 06-08-2014, 05:36 PM
  2. String functions
    By posstrap in forum Access
    Replies: 1
    Last Post: 08-12-2011, 09:08 PM
  3. Replies: 5
    Last Post: 03-10-2011, 02:19 PM
  4. Compiling Data, Not Replacing
    By helpaccess in forum Access
    Replies: 12
    Last Post: 03-08-2011, 03:13 PM
  5. Compiling for distribution
    By wthoffman in forum Access
    Replies: 1
    Last Post: 02-03-2011, 09:34 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