Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLookup #Error Main Form with Sub Form

Status
Not open for further replies.

nogero

Programmer
Mar 1, 2007
43
US
I have a main form named main and a subform named sub. In sub I have a text box named txtresult and I am using a DLookup to show query results and this work fine when just running sub. However, when I load main the txtresult text box shows #Error. I know this has to do with my DLookup syntax but I am unclear on what to use.

My current DLookup syntax is =DLookUp("pscodename_vc","qrypsname")

this is set in the control source for the text box. Any help would be appreciated.
 
What is the SQL code of qrypsname ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
SELECT psplanmaster.pscodename_vc
FROM data INNER JOIN (psplanmaster INNER JOIN cpsplan ON psplanmaster.pspid = cpsplan.pspid) ON data.dataid = cpsplan.dataid
WHERE (((psplanmaster.pspid)=[Forms]!![txtpspid]))
GROUP BY psplanmaster.pscodename_vc;
 
You may try this:
=DLookUp("pscodename_vc","psplanmaster","pspid=" & [txtpspid]"

if pspid is not defined as numeric you have to surround the value with single quotes.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I discovered the answer to my problem. I changed my query to include the full path to the sub-form. Now when you open main it shows the query in the text box on the sub form named sub.


SELECT psplanmaster.pscodename_vc
FROM data INNER JOIN (psplanmaster INNER JOIN cpsplan ON psplanmaster.pspid = cpsplan.pspid) ON data.dataid = cpsplan.dataid
WHERE (((psplanmaster.pspid)=[Forms]![main]!![txtpspid]))
GROUP BY psplanmaster.pscodename_vc;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top