Query Results in Text Box

  • Follow


Hello,

I have an existing form with employee data.  I have just finished
building a query that is a summation of the hours that an employee has
worked at the company.  It is a totals query so it always returns one
answer.  What I would like to do is have the results of the query
appear in the Employee Form (frmEmployees) that I have created.  The
query and form share the common field EmployeeID.  Therefore on the
query, I said the criteria for the EmployeeID was to be [Forms]!
[frmEmployees]![EmployeeID].  When I double click the query and insert
an Employee ID, it gives me the right number.  So I went into the form
and created a text box.  The form itself is based on tblEmployees, so
I went into Properties of the text box, and under control source, put:
[qryEmployeesTotalHours]![SumOfHoursWorked]

When I open the form, the text box has #Name? in it.

Does anyone know what the propblem is?  What I am trying to do is have
it recaculate as the user scrolls through the records (different
employees) of the Employees Form.  Any help would be greatly
appreciated.  If I have posted this in the wrong forum, please let me
know.

Thanks,

John
0
Reply J 3/11/2008 4:15:45 AM

Use DLookup() if you want a text box to read a value from a query.

The Control Source of the text box would be:
    =DLookup("MyField", "MyQuery")
where you substitute the name of your field and query.

If DLookup() is new, here's more on that:
    http://allenbrowne.com/casu-07.html

-- 
Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"J. Trucking" <ptruck@hotmail.com> wrote in message
news:f1ae9b3a-dc07-4c45-978d-2fd5e60d7a89@h11g2000prf.googlegroups.com...
> 
> I have an existing form with employee data.  I have just finished
> building a query that is a summation of the hours that an employee has
> worked at the company.  It is a totals query so it always returns one
> answer.  What I would like to do is have the results of the query
> appear in the Employee Form (frmEmployees) that I have created.  The
> query and form share the common field EmployeeID.  Therefore on the
> query, I said the criteria for the EmployeeID was to be [Forms]!
> [frmEmployees]![EmployeeID].  When I double click the query and insert
> an Employee ID, it gives me the right number.  So I went into the form
> and created a text box.  The form itself is based on tblEmployees, so
> I went into Properties of the text box, and under control source, put:
> [qryEmployeesTotalHours]![SumOfHoursWorked]
> 
> When I open the form, the text box has #Name? in it.
> 
> Does anyone know what the propblem is?  What I am trying to do is have
> it recaculate as the user scrolls through the records (different
> employees) of the Employees Form.  Any help would be greatly
> appreciated.  If I have posted this in the wrong forum, please let me
> know.
> 
> Thanks,
> 
> John
0
Reply Allen 3/11/2008 4:57:52 AM


John, you want to use the DLOOKUP function in your form to read the data
from the query.

Here's a tutorial on DLOOKUP:

http://www.599cd.com/tips/access/dlookup-function/



I hope this helps you. Let me know if you have any more questions or
comments.

Cordially,

Richard Rost
www.599CD.com
www.AccessLearningZone.com

P.S. Visit my web site and watch my 90-minute ACCESS 101 TUTORIAL for free.
Go to www.599cd.com/Access/NG






"J. Trucking" <ptruck@hotmail.com> wrote in message
news:f1ae9b3a-dc07-4c45-978d-2fd5e60d7a89@h11g2000prf.googlegroups.com...
> Hello,
>
> I have an existing form with employee data.  I have just finished
> building a query that is a summation of the hours that an employee has
> worked at the company.  It is a totals query so it always returns one
> answer.  What I would like to do is have the results of the query
> appear in the Employee Form (frmEmployees) that I have created.  The
> query and form share the common field EmployeeID.  Therefore on the
> query, I said the criteria for the EmployeeID was to be [Forms]!
> [frmEmployees]![EmployeeID].  When I double click the query and insert
> an Employee ID, it gives me the right number.  So I went into the form
> and created a text box.  The form itself is based on tblEmployees, so
> I went into Properties of the text box, and under control source, put:
> [qryEmployeesTotalHours]![SumOfHoursWorked]
>
> When I open the form, the text box has #Name? in it.
>
> Does anyone know what the propblem is?  What I am trying to do is have
> it recaculate as the user scrolls through the records (different
> employees) of the Employees Form.  Any help would be greatly
> appreciated.  If I have posted this in the wrong forum, please let me
> know.
>
> Thanks,
>
> John


0
Reply Richard 3/11/2008 9:05:43 AM

Thanks Guys.  I appreciate the help.

John
0
Reply J 3/11/2008 1:40:15 PM

3 Replies
712 Views

(page loaded in 0.062 seconds)


Reply: