Vba access: retrieve a specific value
Solved
arzawe
Posted messages
71
Status
Membre
-
Funstenolf -
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
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 réponses
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à
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à
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