SQL and VBE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • supertsik
    New Member
    • Feb 2007
    • 7

    #1

    SQL and VBE

    Hi! I need help with the following:

    Even though it is quite easy to run SQL UPDATE queries in VBA using the DoCmd.RunSQL, I cannot find a way to run SELECT queries and use the result.

    I have a table with customer names and orders. I want to store the latest orderID of a particular customer in a local variable.

    In short, I would like to run this:

    Private orderid as integer

    orderid = {the result from the query below}
    {SELECT Top 1 Orders.OrderID FROM Orders WHERE Order.customer = "Mr x" ORDER BY Orders.OrderID DESC;}

    Thanks!
  • MSeda
    Recognized Expert New Member
    • Sep 2006
    • 159

    #2
    Since your only looking to return one value a domain aggregate will work.
    Either accesses built in dmax or I like to use Allen Browne’s Elookup.
    They should both yeild identical results in this case, Allen Browne explains the subtle differences at his website.

    orderid = Dmax(“[OrderID]”, “[Orders]”, “[customer] = ‘Mr x’”)
    or
    orderid = Elookup(“[OrderID]”, “[Orders]”, “[customer] = ‘Mr x’”, "[OrderID] DESC"

    hope this helps,
    Megan
    Last edited by MSeda; Feb 21 '07, 03:24 PM. Reason: typo

    Comment

    • supertsik
      New Member
      • Feb 2007
      • 7

      #3
      It does help a lot! Thanks!!!

      Comment

      Working...