Displaying Query Results on a Form

A

Angeline

Hello,
Can someone please help me. I would like to display query results on a form.
I have built a database (most of which without VB but using the functions and
a little help here and there from you wonderful people), and have a form with
in it which consists of buttons that point to queries. I would like the query
results to look 'prettier' and tried linking the button to a 'report' which
displays the query results but I thought it would be much better to display
the results on a form so that it can have the same appearance.
Quick note: I don't know VB so might need a little bit of 'spoon feeding'.
Thanks!!
 
J

Jeff Boyce

Angeline

For one of your queries, use the forms wizard to help you build a form,
based on that query.

In your "button" form (by the way, there are other approaches than adding
one button per query), in one of the button's Click event, create an event
procedure something like:

DoCmd.OpenForm "YourNewFormName"

Substitute the name of the new form you built (see above). You may need to
check Access HELP for help with the syntax, or with Event Procedures.
 
R

Rajat

well u can execute the query from VB & return the result to
recordset......& display the values frm the recordset on the form

sample:
dim db As Database
dim rs As Recordset
dim strSQL As String
Set db = OpenDatabase(database_name, False, True, "M
Access;PWD=passowrd,if any")
strSQL = "Select * from table_name" ' this is sql statement ur gonn
execute
Set rs = db.OpenRecordset(strSQL) 'will execute sql statement & retur
result to recordset

now u can access result from the record set....
eg.
msgbox rs.field(0) ' 1st field in recordset

hope this helped...
 
A

Angeline

HI Jeff,
Thanks for your post (apologies for delay, I'm from Syd AUS)
I will try your suggestion (thankyou) can I ask them if it is possible to
display the results of more than one query on the one form.

Thanks again.
 
A

Angeline

Hi again,
I did as you said and it worked except it only returned one of the results.
I'll explain. This is an 'exit interview' database which captures information
about why employees resign from their employer. This query calculates the
'top reason for leaving' the organisation and is based on an aggregate of all
the responses. The query results return like this:

The two column headers are : Top Reason for Leaving, Percentage
The results are: Pay & Benefits 19%
Learning & Development 21%
Career Opportunities 18% etc

So the query resturns more than 1 value.
 
A

Angeline

Raj,
The query is based on a query that is based on a query and I did not use VB
to write it, I used the front end. I think this might render your suggestion
a little too complicated for my novice mind. I wouldn't know where to start
wrting the code you specified and no, I don't have a password. In any case,
how would I learn VB?

Thank you very much though for your time.\

best regards,
 
J

Jeff Boyce

Angeline

Maybe we need to go back to the beginning. You have queries that you want
to run ... against data. How you query depends on how your data is
structured. Could you describe how your data tables are designed?
 
A

Angeline

HI Jeff,
The main data table is populated from a form. I'm not sure what you mean by
'how is it designed'. I designed the main table in 'design view'. Then I
built a form with several tab to make it easy for a user to populate the main
table. I have built many queries to calculate 'statistical' results. These
are all working perfectly. Many of them however are queries built of queries.

I have set up a second form which is a panel of labelled buttons that
calculate various statistics (based on queries). I was hoping that, instead
of the results displaying in the raw query view - I could have them display
in a form. I can put them in a 'report' for the purposes of looking
'prettier' but from an end user perspective, it would be nicer on a form.

Thanks for your time Jeff
rgs
 
J

Jeff Boyce

Angeline

Sorry, inexact request on my part...

Please describe your data structure (what fields do you have in which
tables?) I'm trying to get a sense of the data elements you are working
with.
 
Top