Help Understanding syntax of DLookUp

Flank

Board Regular
Joined
Dec 12, 2011
Messages
83
Using Access 2007<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I am trying to build a form out that has a number of text fields lookup values from a reference table based on a drop down. <o:p></o:p>
<o:p></o:p>
I thought utilizing the DLookup function would be the way to go, but I just can’t for the life of me understand how to write the syntax properly. <o:p></o:p>
<o:p></o:p>
I have a form called Executed Project Details<o:p></o:p>
The form references a table called Executed Projects<o:p></o:p>
I have a drop down that looks at a table called Project Types.<o:p></o:p>
The project types are as follows:<o:p></o:p>
ID--Project Type<o:p></o:p>
1 Combined Cycle 1x1<o:p></o:p>
17 Combined Cycle 2x1 <o:p></o:p>
33 Biomass<o:p></o:p>
49 AQCS<o:p></o:p>
65 Circulating Fluidized Bed<o:p></o:p>
Based on the selection it stores the ID number in a field called ProjectTypeDesignator<o:p></o:p>
<o:p></o:p>
So based on that designator, I want to lookup the values in another table called ProjectCurves
<o:p></o:p>
ProjectCurves has the following structure<o:p></o:p>
ID---Project Discipline----Month 1-----Month 2<o:p></o:p>
Now that I have selected the project type and know the designator I want to pull Project Discipline, Month 1 and Month 2 into three new texts boxes called Discipline 1, Civil 1 and Civil 2.<o:p></o:p>
<o:p></o:p>
So my thought was to put in a Dlookup for each of the 3 boxes I want to populate based on an AfterUpdate event from the dropdown menu. <o:p></o:p>
<o:p></o:p>
That gives me something like this<o:p></o:p>
Code:
[COLOR=black][FONT=Verdana]Private Sub Combo176_AfterUpdate()
   
Me.Discipline_1 = DLookup("Project_Discipline", "ProjectCurves", Me.ProjectTypeDesignator)
Me.Civil_1 = DLookup([Month 1], "ProjectCurves", Me.ProjectTypeDesignator)
Me.Civil_2 = DLookup([Month 2], "ProjectCurves", Me.ProjectTypeDesignator)
End Sub<o:p></o:p>[/FONT][/COLOR]
<o:p> </o:p>
However upon the after update event, I get a Run-time error 2471:<o:p></o:p>
The expression you entered as a query parameter produced this error: ‘Project_Discipline’<o:p></o:p>
<o:p> </o:p>
I am now stumped…<o:p></o:p>
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Wow seems so easy now after looking at that, thank you.

That link made a lot more sense than the help file in Access

I made a little change and boom it worked.
Code:
Private Sub Combo176_AfterUpdate()
   
Me.Discipline_1 = DLookup("[Project Discipline]", "ProjectCurves", "ID = " & Me.ProjectTypeDesignator)
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,212
Members
453,151
Latest member
Lizamaison

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top