I want to pull a value from one field on a query that contains only one record, so that I can then use it in a calculation and I dont seem to be able to correctly do it.
you could use DLookup to get the value.
Example, me.txtFieldValue = Dlookup
For a string value
("[FieldName]", "queryName", "[SomeField] ='" & Somevalue & "'"
For a numerical value
("[FieldName]", "queryName", "[SomeField] =" & Somevalue)
This assumes you know the value of some field from the query already.
These are just random samples & I could help with your particular TextBox if you post specifics
WARNING: Over use of domain aggregate function can *really* slow up the system. I just use them in onesies & twosies more than that & I rethink the design.
Thanks rafe and ntp for your answers, I am still missing something though.
The text box on my form called 'frmCeilings' is named 'txtMainTcost' and I want to put in the value held in the field named
'Cost per Metre' from the Query named 'MainTeesQ'
I have been trying to do this as per your advice for example
=DLookUp("[Cost per Metre]","MainTeesQ","[txtMainTcost] =" & [txtMainTcost])
but I must be doing something wrong as it is not working.
=DLookUp("[Cost per Metre]","MainTeesQ","[txtMainTcost] =" & [txtMainTcost])
This is wrong. the lookup function is used like this:
Dlookup(field1, table, field2 = value)
field1 - the field whose value you want to return
table - the name of the table/query the field belongs to
field2 - the name of a field whose value you know, e.g a ID field
value - the value of field2 that you know
So your code should be
me.txtMainTCost = DLookUp("[Cost Pre Metre]", "MainTeesQ", "[MianTeesQID] =" & IDValue)
This assumes that MinaTeesQID is the primary key from MainTeesQ and IDValue is the value of the record whoose [Cost Per Metre] you want.
also remember those single quotes surrounding text fields that were in ntp's original post. so if [txtMainTcost] is a text field you would change your line to the following...
=DLookUp("[Cost per Metre]","MainTeesQ","[txtMainTcost] ='" & IDValue & "'"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.