Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Tunbridge Wells, Kent. UK

    Question Unanswered: Using variables?!?!

    Can you use a value that is returned from a query, by assigning that value to a variable?

    Thanks in advance

  2. #2
    Join Date
    Mar 2004
    explain more please,

    first impression :

    place de sql of query in a sub or function like

    private sub XXXX () as string (or integer or what´s necessary)

    XXXX = sql statement

    end sub

    btw my sql experience is not to talk about :-))), but something like such is possible to my opnion.

  3. #3
    Join Date
    Dec 2002
    Préverenges, Switzerland
    the simple answer is NO: a query potentially returns thousands of rows, each with potentially many fields - there is no obvious way to stick a generic query-return into "a" variable.

    there are two possibilities that might suit you depending on what you are trying to do.

    domain aggregate functions behave a lot like queries and return (guaranteed) one value so their return sits happily in a variable.
    the domain aggregate equivalent of a SELECT is DLOOKUP() e.g.

    myVar = DLOOKUP("fieldNameInQuotes", "tableNameInQuotes", "criteria")

    criteria is EXACTLY the same as the WHERE clause in normal SQL but without the word "WHERE". criteria examples:
    "myID = 2"
    "myID = " & Forms!ThisForm.IDbox

    check our DCOUNT() DMAX() DMIN() DLOOKUP() etc in Help.

    if you want to play with more than one field and/or more than one record in vars, search this site for "recordset" (it comes up 50 times a month)

    currently using SS 2008R2

Posting Permissions

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