• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

Can global variable be updated from Access query

Can I directly assign a query's returned (max) field value to a global variable? How?
0
glentek
Asked:
glentek
3 Solutions
 
harfangCommented:
Hello glentek

    variable = dmax("field", "table", "criteria=true")

or, also "direct":

    variable = currentdb.openrecordset("select max(field) from table").fields(0)

Cheers!

(°v°)
0
 
rockiroadsCommented:
Harfang has given u the VBA way which may be the easier to code. My personal choice would be to use DMAX if u just have the one table to lookup.

If u wanted it to do it in a query, u can make use of query functions
e..g

SELECT SetVar(max(fld)) from table


but then u have to have a public procedure - so we are back to VBA

Public Function SetVar(ByVal sVar As String)
    g_sGlobalVar = sVar
End Function

0
 
GRayLCommented:
Global variables are normally set before any functions or subroutines in a module.  Those areas are not available to to Jet and the results of queries.  You can programatically alter the contents of a module via VBA but you asked specifically if it could be done from a query - no!
0
 
Wayne BarronCommented:
Hello GRayl;

Would you mind taking a look at the following Post?
http:Q_21878745.html
Thanks a bunch.

Carrzkiss
0
 
Wayne BarronCommented:
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now