Results 1 to 2 of 2
  1. #1
    sdmpp5 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2016
    Posts
    2

    Declaring Logical Operator in Function to be Used in Query

    Is there a way to declare a logical operator (ie: <=, >, etc...) in a module to be referred to in various queries? I have multiple queries that require the same criteria but only want to have to update the criteria in one location if possible. I have been using the following language but get a data type mismatch when I use the function in my select query criteria. I query works when I drop the "<=" in the below language. I have also tried the second set of language (below), yet that does not work either.

    [code]
    Function TestCriteria()
    TestCriteria = "<=4"

    End Function
    [code]

    -----

    [code]
    Function TestCriteria()
    TestCriteria = "<=" & 4

    End Function]
    [code]

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    nope, only by building the sql in vba.

    Alternatively declare in a module (not a form module) - something like

    Code:
    Public Function TestCriteria(Fld as integer; Crit as String) as Boolean
    
         TestCriteria = eval(fld & Crit)
     
    End Function
    then in your query, something like
    Code:
    SELECT *
    FROM myTable
    WHERE testcriteria([fieldname,"<=4")

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

Similar Threads

  1. declaring a Global variable
    By George in forum Forms
    Replies: 3
    Last Post: 05-24-2016, 09:33 AM
  2. logical operator as a variable (syntax?)
    By markjkubicki in forum Programming
    Replies: 5
    Last Post: 03-11-2015, 10:59 AM
  3. Query Criteria Function and Operator List?
    By samanthaM in forum Access
    Replies: 2
    Last Post: 06-03-2012, 04:52 PM
  4. Error Declaring FK and PK on same Line
    By jo15765 in forum SQL Server
    Replies: 0
    Last Post: 01-21-2012, 04:29 PM
  5. How to create a query for logical combo??
    By valkyry in forum Queries
    Replies: 1
    Last Post: 10-08-2007, 02:32 PM

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
  •  
Other Forums: Microsoft Office Forums