Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2007
    Posts
    18

    Unanswered: If length of string greater than...create a error

    Hello guys,

    I have a query (expr1) that combines all my data into one string/line of characters.

    example
    "10321392193j34929339294900000000000"

    I was wondering if anyone knew how to throw an error if that string length if greater than over 150 characters. Something like...

    If len > 150 then

    Then i would have it go to my error msgbox. But for now i need to know how to throw the error linking it to that query (name is: expr1).

    Thanks

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    If you want it to be part of the query itself, use something like...

    IIF(LEN(EXPR1)<151, EXPR1, "STRING TOO LONG")
    Inspiration Through Fermentation

  3. #3
    Join Date
    Jan 2007
    Posts
    18
    thats works great within the query like you said, can I use it to make an if then function within a module.

  4. #4
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Yes, it can be broken down into If...Then...Else for use in a module.

    Code:
    Dim rs AS RECORDSET
    ...
    strsql="Select field1 & " " & field2 as Expr1 from sometable" 
    RS.OPEN YOURCONNECTION, STRSQL
    ...
    If len(rs!Expr1)<151 Then
    ...
    Else
    ...
    Last edited by RedNeckGeek; 01-30-07 at 16:54.
    Inspiration Through Fermentation

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    iif() statements are nothing more than condensed if..then statements:

    iif(<condition>, <valueiftrue>, <else>)


    if len(expr1) < 151 then
    expr1
    else
    "string too long"
    end if
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •