Trying to populate a text field on a form with a DLookup

I'm using this code in the control source property of a textbox on a form and all I get is #Name?

The form is a datasheet view form if that matters.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
don't see any code...

SteveL13Author Commented:
Sorry...  Forgot to paste it...

=DLookUp("[FullName]","tblPersonnel","[ID] = " & [Forms]![subfrmIssueDS]![txtOpenedBy])
Eric ShermanAccountant/DeveloperCommented:
If [FullName] is a Text field in your table then this should work ...

=DLookUp("[FullName]","tblPersonnel","[ID] = '" & [Forms]![subfrmIssueDS]![txtOpenedBy] & "'")

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

SteveL13Author Commented:
FullName is text but ID is a number
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Often that means something is misspelled. Be sure your field, table, form and control names are right.

Also, I'm not sure you need square brackets around the names:

=DLookUp("FullName","tblPersonnel","ID =" & [Forms]![subfrmIssueDS]![txtOpenedBy])

You might also need to trap for NULL values:

=Nz(DLookUp("FullName","tblPersonnel","ID =" & [Forms]![subfrmIssueDS]![txtOpenedBy]), "No Value")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
Still not working.  I'll have to strip sensitive "stuff" out and attach a database.
SteveL13Author Commented:
Sample attached.  The problem is with the form...  frmIssueDSheader

(Plus the search "thing" isn't working but that's another issue).
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
This works in the OpenedBy box in your subform:

=Nz(DLookUp("FullName","tblPersonnel","ID =" & [txtOpenedByN]),"No Value")

This works in the txtAssignedTo box in your subform:

=Nz(DLookUp("FullName","tblPersonnel","ID= " & [cboAssignedTo]),"No Value")

That said - you could just join tblPersonnel to tblIssues (twice), and use the values from there, instead of using a DLookup. I made those changes in the file and uploaded.

I'd also caution you against setting up combos and such on columns at the table level. There is absolutely no good reason to do so, and lots of very good reasons to NOT do so.
I can't download the .accdb due to an IE error but #Nameis often caused because the control name is the name of a column in the form's RecordSource but the controlSource contains an expression (anything that starts with =) rather than the name of the bound column.

When you let a wizard build a form/report or when you drag a field on to a form/report from the field list, Access Assigns the ControlName to be the same as the ControlSource.  So if the column in the table/query is DeptName, then the ControlSource ends up being DeptName and so does the ControlName.  If you then change ControlSource to something like =[DeptNum] & " - " & [DeptName], you will get the #Name error.
Eric ShermanAccountant/DeveloperCommented:
Sorry, I misread your Dlookup statement ... I thought you were looking for FullName.

Eric ShermanAccountant/DeveloperCommented:
I opened your sample DB ... Your DLookup statement seems to be working.  Can you explain further??

Sample Form
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
etsherman: That was the one I uploaded, after fixing the DLookup issue.
Eric ShermanAccountant/DeveloperCommented:
Ok .... Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.