Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to bind a text box on a form to a specific field?????

Status
Not open for further replies.

fargo

Programmer
Nov 9, 2000
63
0
0
GB
Maybe I'm doing it all wrong but here goes.

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.

Can anyone help.

Thanks
 
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.

ntp
 
Try using the domain aggregate functions instead. They’re actually mini-queries that you use as a control's data source.

As an example, if I wanted to get may last name from the Personnel table via my Nickname I’d set the TextBox's ControlSource to...

=DFirst("[LastName]","Personnel","[NickName]='Rafe'")

You can also use domain aggregate functions in equations like…

=DSum("[Amount]","Payments","[Type]=30")-1000000

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.

Thanks
 
=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.

Hope this clears things up.

ntp
 
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 & "'")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top