Solved

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

Posted on 2014-10-23
13
232 Views
Last Modified: 2014-10-29
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.

--Steve
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +2
13 Comments
 
LVL 58
ID: 40400412
don't see any code...

Jim.
0
 

Author Comment

by:SteveL13
ID: 40400416
Sorry...  Forgot to paste it...

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

Expert Comment

by:Eric Sherman
ID: 40400440
If [FullName] is a Text field in your table then this should work ...

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

ET
0
Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

 

Author Comment

by:SteveL13
ID: 40400445
FullName is text but ID is a number
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40400517
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")
0
 

Author Comment

by:SteveL13
ID: 40400525
Still not working.  I'll have to strip sensitive "stuff" out and attach a database.
0
 

Author Comment

by:SteveL13
ID: 40400535
Sample attached.  The problem is with the form...  frmIssueDSheader

(Plus the search "thing" isn't working but that's another issue).
Example.accdb
0
 
LVL 85
ID: 40400581
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.
Example--1-.accdb
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 40400591
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.
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 40400681
Sorry, I misread your Dlookup statement ... I thought you were looking for FullName.

ET
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 40400703
I opened your sample DB ... Your DLookup statement seems to be working.  Can you explain further??

Sample Form
0
 
LVL 85
ID: 40401879
etsherman: That was the one I uploaded, after fixing the DLookup issue.
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 40401917
Ok .... Thanks
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question