Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    994
    Provided Answers: 2

    Unanswered: Performing comparisons with operators held in variables

    Hi All

    I've managed to paint myself into a corner in a database. I have a series of tables that define periodic and irregular KPIs that are recorded for a website. I also have a series of forms that I use to add new records.

    Having got bored ticking a box to indicate whether a KPI passed or not, I decided to create another table to hold the passing criteria (check ID, criteria description, trigger (score value - numeric) and comparison (=, <, >, etc).

    I have coded everything to deal with maintaining the above. I can work out how to pull the trigger and comparison operator into variables. I cannot figure out how to use those variables to determine if the value passes or not.

    To lillustrate:
    Code:
    Function IsSuccess(lngID as Long, dblScore as Double) As Variant
    
    Dim varData as Variant
    Dim dblTrig as Double
    Dim strComp as String
    Dim strSQL as String
    
    varData = DLookup("[Data]", "vwSuccessCheck", "[CheckNo] = " & lngID)
    
    If IsNull(varData) Then
    IsSuccess = Null
    Exit Function
    End If
    
    dblTrig = CDbl(FINDWORD(varData, 5, "~")
    strComp = FINDWORD(varData, 4, "~")
    
    IsSuccess = dblScore strComp dblTrig
    
    Exit Function
    How do I build a comparison statement with my comparison operator in a variable?
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Not sure whether it's what you're looking for or not but you should have a look at the Eval() function in Access help.
    Have a nice day!

  3. #3
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    994
    Provided Answers: 2
    That's exactly it - thank you!

    (I am now kicking myself, BTW. Most of my time at work is spent wearing a Lotus Notes hat, and in that flavour of VB, there is a function Evaluate that will parse and process an expression that results in a valid Formula language statement...)
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

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
  •