Vba access: retrieve a specific value

Solved
arzawe Posted messages 71 Status Member -  
 Funstenolf -
Hello,

I am looking to retrieve a specific value from a table with the following formula:

sql = "SELECT [Ratios]![HMO total] FROM [Ratios] WHERE [Ratios]![Ligne] = 'TOTAL - U2"
MsgBox = sql

But what it gives me in my msgbox is my formula. What I want is the number it corresponds to in the table.

What is missing in my formula?

Thank you for your help
--

Arzawe
Configuration: Windows XP Internet Explorer 6.0

6 answers

  1. Velvel-Miho Posted messages 32 Status Member 21
     
    variable :
    Dim requete As Recordset
    Dim sql As String
    Dim resultat As Currency

    code d'exécution de la requête :
    sql = " SELECT champ1, champ2, ... FROM table WHERE ... ;"
    Set requete = CurrentDb.OpenRecordset(sql)
    première ligne de résultat :
    requete.MoveFirst
    resultat = requete("champ1")

    et enfin tu affiches resultat

    Voilà
    15
    1. arzawe Posted messages 71 Status Member 5
       
      Thank you for your answers, but I found another solution by digging a little deeper:

      mavariable = DLookup("[HMO total]", "[Ratios]", "[Ratios]![Ligne] = 'TOTAL - U2'")

      where HMO total is my column
      Ratios is my table
      and the third expression is my criteria.

      So, no need to go through SQL
      --

      Arzawe
      0
    2. danièle21
       
      Hello, and if multiple values match your criteria, does the DLookup function retrieve all these values as well?
      -1