By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,400 Members | 981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,400 IT Pros & Developers. It's quick & easy.

How to show a query result on a form

P: 93
Hi Everyone

I have a query which shows total number of hours and I want to display this information on a form (as a text box or a label).

How can I do it?

Thanks in advance
Dec 7 '07 #1
Share this Question
Share on Google+
13 Replies


puppydogbuddy
Expert 100+
P: 1,923
Hi Everyone

I have a query which shows total number of hours and I want to display this information on a form (as a text box or a label).

How can I do it?

Thanks in advance
You can use the DLookup function as follows:

YourTextbox = DLookup("[TotalHours]" , "YourQuery")

The DLookup rather than DSum was used because the You stated that the summation is done in the query itself.
Dec 7 '07 #2

P: 93
Thanks for the reply it is working :)

What I need to do now is to show total field on the form based on a query where there are 7 different rows [employeeID] and I need to extract the total of the employeeID which is choosen from the combo box on the form.

Any ideas how to do it?

Thanks in Advance
Dec 8 '07 #3

puppydogbuddy
Expert 100+
P: 1,923
Thanks for the reply it is working :)

What I need to do now is to show total field on the form based on a query where there are 7 different rows [employeeID] and I need to extract the total of the employeeID which is choosen from the combo box on the form.

Any ideas how to do it?

Thanks in Advance
Again, I am using DLookup rather than DSum because, if I understand you correctly, your query has the total for each employeeID, hence you just need to look up that total. You would use DSum if the query has several entries for each employeeID that have to be totaled.

try this if EmployeeID is a numeric data type in your table.

YourTextbox2 = DLookup("[TotalHours]" , "YourQuery", "[EmployeeID] = " & Me!YourCombo)

try this if EmployeeID is a text data type in your table.

YourTextbox2 = DLookup("[TotalHours]" , "YourQuery", "[EmployeeID] = '" & Me!YourCombo & "'")
Dec 8 '07 #4

P: 93
Thanks so much!!!! Functions will make my work so much easier :)
Dec 8 '07 #5

P: 93
I tried to use the function but I have an error #name? when I used me!combo8 (in my case)?

I presume the problem occurs because the combo box holds a string value and the query shows a string values but it is an integer.

The function is working when I replace me!combo8 with number 18 (John)

Any ideas???
Dec 9 '07 #6

puppydogbuddy
Expert 100+
P: 1,923
I tried to use the function but I have an error #name? when I used me!combo8 (in my case)?

I presume the problem occurs because the combo box holds a string value and the query shows a string values but it is an integer.

The function is working when I replace me!combo8 with number 18 (John)

Any ideas???
Place your table in design view and look up the data type of EmployeeID. Depending on the data type show, choose the applicable one of the two syntaxes I gave you. If the numeric syntax does not work, then try the text syntax. If neither work, I suspect that you misspelled object name or used the wrong case (object names are case sensitive).
Dec 9 '07 #7

P: 93
I do realise that I could have made a mistake (misspelled control etc) but I cannot find it.

if anyone is interested I can send a sample *.mdb
***email removed by moderator***

Thank you for your patience.
Emil
Dec 9 '07 #8

puppydogbuddy
Expert 100+
P: 1,923
If the function is working when you replace me!combo8 with number 18 (John)

Try these suggestions one at a time.
1. When you typed the syntax I gave you, did you include the ampersand & as shown in the example?
2. When you checked names and spelling, did you check against the name property shown in the property sheet for that control?
3. Replace Me!combo8 in the expression with Forms!YourForm!combo8 .use the actual name of your form in place of "YourForm"
4. You tried both syntaxes I gave you?
Dec 9 '07 #9

P: 93
Hi I really want to know what I'm doing wrong, so I created a simple database and the form and here is the link.A sample
Dec 10 '07 #10

puppydogbuddy
Expert 100+
P: 1,923
Hi I really want to know what I'm doing wrong, so I created a simple database and the form and here is the link.A sample
I looked at your sample. The table test is different than you described above. You are trying to sum a non-numeric field. You can count it , but you can't sum it. Also, your table has no unique identifier (pimary key), which won't prevent you from using it but will cause problems later on. You need to take some of the tutorials available thru this site to learn the basics before you proceed.
Dec 10 '07 #11

P: 93
My question was just to lookup a value in the query (I don't want to sum anything)

(there isn't a primary key because it is not the database I use, I just created it as a sample)

I have used the function Dlookup but when I want to lookup a value in a query based on the combo box value (me!comboboxname) I have an error #name? when I use the same function and instead of me!comboboxname I put 1 or 2 I have the correct result (check 2 text boxes below the error text box)
Dec 11 '07 #12

puppydogbuddy
Expert 100+
P: 1,923
My question was just to lookup a value in the query (I don't want to sum anything)

(there isn't a primary key because it is not the database I use, I just created it as a sample)

I have used the function Dlookup but when I want to lookup a value in a query based on the combo box value (me!comboboxname) I have an error #name? when I use the same function and instead of me!comboboxname I put 1 or 2 I have the correct result (check 2 text boxes below the error text box)
Emil,
OK, I understand your question now. The answer is that Me is something that you can use in code, but not in an expression involving the control source. You have to use the full reference >>>>Forms!frmTest<<<< in the expression dor the control source instead of Me.
Dec 11 '07 #13

P: 93
Thanks for your help it's working now.
Dec 12 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.