The expression needs to be put in the Control Source property for the
textbox if you just want to display it. If you want to put the value into
that control so that it's stored in a field in the table (usually this is
not necessary, as you can always look up the value again via a query or
control on a form), then you'd use the AfterUpdate event to run the code
that you posted (after fixing the syntax errors, that is).
It appears that both the Professor field and the Course field are text data
type fields. What I'd provided was how to do it for a number field, not a
text field. When your "matching" value is a text string, you must delimit it
with ' characters.
Assuming that both are text fields, this is what you'd put in the
ControlSource:
= DLookup("mail", "TAFQry", "[Professor]='" & [Professor] & "' And
[Course]='" & [Course] & "'")
If you run it via AfterUpdate code:
Me.MailInst = DLookup("mail", "TAFQry", "[Professor]='" & Me.Professor.Value
& "' And [Course]='" & Me.Course.Value & "'")
--
Ken Snell
<MS ACCESS MVP>
David said:
Ken,
Thank you so far. I tried a few things using your suggestion and I'm doing
soemthing wrong with it.
First I placed your suggestion in the control for field 3 like this
LookedUpValue = DLookup("mail", "TAFQry", "[Professor]=" &
Me.Professor.Value & " And [Course]=" & Me.Course.Value)
Result : ?Name
Then I tried this
= DLookup("mail", "TAFQry", "[Professor]=" & Me.Professor.Value & " And
[Course]=" & Me.Course.Value)
result : ?Name
So then I put the control back to MailInst
and then used a Afterupdate expression
Me.MailInst = (DLookup("Mail", "Taf", "[professor]=" & Me.Professor.Value &
" And [course]=" & Me.Course.Value))
Result: Syntax Error (misiing operator) in query expression "[professor] =
wiley and [course] = Bpa 125
If you can help me further with this, Thank you again
David
Ken Snell said:
Assuming that you're wanting to use the controls on the form:
LookedUpValue = DLookup("FieldName", "TableName", "[Field1]=" &
Me.Control1.Value & " And [Field2]=" & Me.Control2.Value)
--
Ken Snell
<MS ACCESS MVP>
Hello,
I have one form with a total of three fields. This form is based of lets
say Table1. I would like to use the data in field 1 and 2 together to
lookup
in table2 for the data for field 3. I cant figure out how to use Dlookup
for
this.
Any help would be great thank you
David