Result from query into label.caption ?

  • Thread starter Thread starter SpookiePower
  • Start date Start date
S

SpookiePower

I'm going to make a tabpage containing some statistics.
The statistics do I calculate with use of querys and the
result from the querys I want to be displayed in a label.

My guess was to do it this way -

Labelname.Caption = DoCmd.OpenQuery "queryName"

but it does not work. What do I do wrong ?
 
Labels don't display query results. Consider looking at listbox controls.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
I'm going to make a tabpage containing some statistics.
The statistics do I calculate with use of querys and the
result from the querys I want to be displayed in a label.

My guess was to do it this way -

Labelname.Caption = DoCmd.OpenQuery "queryName"

but it does not work. What do I do wrong ?

If the query returns just one record, you can use, in VBA:

LabelName.Caption = DLookUp("[ColumnName]","QueryName")

If the query reeturns more than one record, you can still use DLookUp
but you will need to add a Where clause to find the correct value.
See DlookUp as well as "Restrict data to a subset of records" in VBA
help.

If you wanted to show more than one column on the label, you can use:
Labelname.Caption = LabelName.Caption & "StatisticA " &
DLookUp("[StatisticA]","QueryName") & vbNewLine
Labelname.Caption = LabelName.Caption & "StatisticB " &
DLookUp("[StatisticB]","QueryName") & vbNewLine
etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top