D
David
How do I use a textbox on a form with a DLookUp() function
to display data from a table?
to display data from a table?
Paul Johnson said:The format for dLookup is:
dLookup(strExpression,strDomain,strWhereCondition)
The parameters are all string values. StrExpression is the table field
whose value you are looking up. StrDomain is a table or saved query object.
If you have spaces in the names of your field or table, you must enclose
them in square brackets as well as quotes: "[Last Name]","[My Table]"
Example of common usage:
dLookup("ZipCode","tblCustomers","CustID=" & me.cboCustomer)
This made-up example assumes you have a combobox cboCustomer on your form
that is based on the numeric CustID field. If the Where Condition includes
a text value, it needs to be spelled with quotes-in-quotes:
dLookup("ZipCode","tblCustomers","CustName='" & me.txtCustName & "'")
Note use of single quotes in third parameter. Some prefer "CustName=" &
Chr(34) & me.txtCustName & Chr(34), but single quotes are enough. It's
harder to see the single quotes in code, but easier to type-- personal
preference applies here.
HTH
Paul
David said:How do I use a textbox on a form with a DLookUp() function
to display data from a table?
Michel Walsh said:Hi,
You don't need to care about the delimiters if you use the syntax
FORMS!FormName!ControlName, and keep it INSIDE the string:
dLookup("ZipCode","tblCustomers","CustID=FORMS!FormNameHere!cboCustomer")
That is working for Dxxx domain functions, and DoCmd methods, but NOT
for CurrentDb (or database objects) methods.
Hoping it may help,
Vanderghast, Access MVP
Paul Johnson said:The format for dLookup is:
dLookup(strExpression,strDomain,strWhereCondition)
The parameters are all string values. StrExpression is the table field
whose value you are looking up. StrDomain is a table or saved query object.
If you have spaces in the names of your field or table, you must enclose
them in square brackets as well as quotes: "[Last Name]","[My Table]"
Example of common usage:
dLookup("ZipCode","tblCustomers","CustID=" & me.cboCustomer)
This made-up example assumes you have a combobox cboCustomer on your form
that is based on the numeric CustID field. If the Where Condition includes
a text value, it needs to be spelled with quotes-in-quotes:
dLookup("ZipCode","tblCustomers","CustName='" & me.txtCustName & "'")
Note use of single quotes in third parameter. Some prefer "CustName=" &
Chr(34) & me.txtCustName & Chr(34), but single quotes are enough. It's
harder to see the single quotes in code, but easier to type-- personal
preference applies here.
HTH
Paul
David said:How do I use a textbox on a form with a DLookUp() function
to display data from a table?