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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to display the results of a query in an txt box? 3

Status
Not open for further replies.

Enea

Technical User
Feb 23, 2005
90
0
0
US
I have created a little training log for myself.
When I select an activity from a dropdown box I would like to immediately display a weekly total (time engaged) for that activity.

I already have the query but what I would like to know is:
is it possible to display the result of the query in my form. If yes, how do I do that?

SELECT [qryWeeklyTotals].[WeeklyTotals]
FROM qryWeeklyTotals
WHERE [qryWeeklyTotals].[activity]=[forms]![frmLog]!activity;

 
How are ya Enea . . .

Sure! Return the value(s) from a function based on a recordset:
Code:
[blue]Public Function WkTlt()
   Dim db As DAO.Database, rst As DAO.Recordset
   Dim Build As String, SQL As String, NL As String
   
   Set db = CurrentDb
   NL = vbNewLine
   SQL = "SELECT [WeeklyTotals] " & _
         "FROM qryWeeklyTotals " & _
         "WHERE ([activity]=" & [Forms]![frmLog]!activity & ");"
   Set rst = db.OpenRecordset(SQL, dbOpenDynaset)
   
   If Not rst.BOF Then
      Do
         If Build = "" Then
            Build = Format(rst!WeeklyTotals, "Currency")
         Else
            Build = NL & Format(rst!WeeklyTotals, "Currency")
         End If
         
         rst.MoveNext
      Loop Until rst.EOF
   End If
   
   WkTlt = Build
   
End Function[/blue]
Then something like:
Code:
[blue]   Me![purple][b]TextboxName[/b][/purple] = WkTlt()
or
   =WkTlt()[/blue]

Calvin.gif
See Ya! . . . . . .
 
You may simply consider the DLookUp function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Wonderful. Thank you AceMan1. :)

Thank you PHV for suggesting an alternative option.
 
What I have always done is displayed it in a listbox (sized like a textbox) and put the SQL as the Row Source.

Since I'm not an expert (or even an intermediate), I don't know if there is a reason NOT to do it this way. But it definitely works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top