Using DLOOKUP in VBA

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

I am trying to write some code which will create a new
record in a table based on the fields on an open form, but
I want to populate one field in the table with data drawn
from another table. I tried inserting the following line
in the code but it keeps falling over. Has anyone any
ideas?

CurrTab!From = DLookup("[FullName]", "tblUsers", "[Lan-ID]
=" & Me![Lan-ID])

I am trying to write the contents of the field "Fullname"
from the table "tblUsers" to a field called "from" in the
new table. The linking fields on the form and in the
table are both called Lan-ID.
 
Remove the [ ] from around FullName in the first argument:

CurrTab!From = DLookup("FullName", "tblUsers", "[Lan-ID]=" & Me![Lan-ID])
 
Tim said:
I am trying to write some code which will create a new
record in a table based on the fields on an open form, but
I want to populate one field in the table with data drawn
from another table. I tried inserting the following line
in the code but it keeps falling over. Has anyone any
ideas?

CurrTab!From = DLookup("[FullName]", "tblUsers", "[Lan-ID]
=" & Me![Lan-ID])

I am trying to write the contents of the field "Fullname"
from the table "tblUsers" to a field called "from" in the
new table. The linking fields on the form and in the
table are both called Lan-ID.


What does "falling over" mean?

By itself, your statement look OK to me, but I have to
wonder what type field Lan-Id is. If it's a Text field,
then the DLookup should be written as:

DLookup("[FullName]", "tblUsers", "[Lan-ID] =""" &
Me![Lan-ID] & """")
 
Back
Top