Using DLOOKUP in VBA

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

Ken Snell

Remove the [ ] from around FullName in the first argument:

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

Marshall Barton

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] & """")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Using DLOOKUP in code entries 7
DLookup Error 3
DLookup 2
DLookup Issue 9
DLookup Problem 1
Saving fields from a form to a table 2
What's wrong with this? 2
Dlookup in table won't work 2

Top