Link to home
Start Free TrialLog in
Avatar of repco
repco

asked on

Get value from Query in VB

Hello,

i need to get a value from a different query into an unbound tex box so i can compare if that value = to a value in that form. this is what i have so far and i'm not sure if this is the right way. calcdir is the name of the unbound text box, but it just gives me a blank result.

Dim rsDir As DAO.Recordset
Dim sql As String
sql = "SELECT [Registers - Totals].SumOfDir FROM [Registers - Totals]"
Set rsDir= CurrentDb.OpenRecordset(sql)
calcdir = rsDir

any suggestions? thanks!
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

use dlookup

=dlookup("ValueField","nameOfQuery",<criteria>)
post the name of the query and the column you want to get the value from
ASKER CERTIFIED SOLUTION
Avatar of Eddie Antar
Eddie Antar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dim rsDir As DAO.Recordset
Dim sql As String
sql = "SELECT [Registers - Totals].SumOfDir FROM [Registers - Totals]"
Set rsDir= CurrentDb.OpenRecordset(sql)

if rsdir.EOF then
   msgbox "No records"
   exit sub
end if
Dim rsDir As DAO.Recordset
Dim sql As String
sql = "SELECT [Registers - Totals].SumOfDir FROM [Registers - Totals]"
Set rsDir= CurrentDb.OpenRecordset(sql)

if rsdir.EOF then
   msgbox "No records"
   exit sub
end if

calcdir = rsDir("SumOFDir")
correction:
Add this instead of the statement calcdir = rsDir

calcdir = rsDir![SumOfDir]