I am doing my first DLookup.  I have a form who's record source is a table called Caller Info.  The form is also called Caller Info and has a combo box field called Customer.  When the user selects a customer from the drop down list, the form needs to reference a short table (called Customer) that establishes the relationship between the Customer and  the customer's corresponding Number_system.  Then it needs to put the Number_system in a text box on the form.  In other words, I need it to automatically fill that field (text box) based on the Customer that the user chooses.  This is the line of code that I currently have in the text box properties Control Source.  

Number_system.Value=DLookup("[Number_system]![Customer]", "[Number_system]="&Customer.Value)

The test box is currently giving me a #Name? error.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

GRayLConnect With a Mentor Commented:
Get rid of the spaces in form, report, control, field and table names.  Lets go for CallerInfo.  Never give objects such as tables and forms the same name - lets go for tblCallerInfo and frmCallerInfo.  Never give controls and fields the same name - lets go for fldName1 and tbxName1.  Getting the picture?

Normally you prefix the name of a control on a form or a report with a prefix denoting the type of control:  cbo -combobox, tbx - textbox, lbx - listbox, cmd - command button, etc.  The naming can be anything you like an you should try and restrict it to three characters.  Thus in code you always know when you are referring to a control cboDrID versus a field fldDriID.

As to the DLookUp()

=DLookUp("myFld","myTable","myCriterion1 AND myCriterion2 AND etc.")

Just my 2¢.
The syntax for a DLookup statment is:

DLookup("YourFieldNameAsSeenInTheTable", "YourTableName", "SomeOtherField = " & Me.cboYourCombo)

However, it sounds like  you would be better off with a combo box that selects both fields in its rowsource (You can set the width of the column you don't want to see to zero).

The control source of your textbox would look something like this, including the = sign (no VBA needed):

= cboYourCombo.Column(1)
Also note that column numbers are Zero-based.  So the first column is 0 then 1,2,3 etc.

Can you provide some feedback please?
Thanks, but what was missing in my explanation?  It was your first DLookup.  I told you what was wrong.  Just as soon you kept the points than award a B!
All Courses

From novice to tech pro — start learning today.