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!

How do I show query results in a form?

Status
Not open for further replies.

nakedbamboo

Technical User
Oct 8, 2003
36
0
0
US
I am sure this is easy to do, but I can't find any reference to it. I am trying to run a query and instead of displaying the results in tabular form, open up a form to browse the records one at a time. I cannot figure out how to open the form and put the results into it. At the same time I am saving the query results to a file. Below is the code I am trying to get working:

Query name - AlumniSearch
Form for search results - SearchResults

Dim FileName As String
Dim frm As Form

DoCmd.OutputTo acOutputQuery, "AlumniSearch", acFormatXLS, FileName


Set frm = CreateForm(, "SearchResults")
DoCmd.Restore
frm.RecordSource = "AlumniSearch"


Currently this just opens up a blank form in design mode. It does save the results correctly.
 
I am assuming that your only reason for doing this is so that you can view individual records at once, and that you are doing this from MS Access. If so, do you need to use code? or is it ok for your needs to create the query and click the new object button and create a form based on the query?
Jim
 
Ooops, my bad. I didn't pay attention to your code. I see that you are saving the results to excel. You could of course still follow my suggestion, and then analyze in excel. Sorry for the bad, Jim
 
I have gotten a little further now. I have gotten the query to pop up the correct form, but cannot get it to populate the form with the records. I am using this command now:

DoCmd.OpenForm "SearchResults", , "AlumniSearch"

It opens the form "SearchResults", but it is blank. I would like to open the form filled with data from records obtained from the query "AlumniSearch". I have thought of the new object button option, but was trying to just get it all to happen with the click of one button. Currently it saves everything great, but I was also wanting to give the user the option of browsing the records one by one in a form that is easier to digest than a table.

I don't know if it matters, but the query is based on information filled out in another form (a query by form). After they fill the fields they want to search by, they click a button and that is when I want all this to happen.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top