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

Access display control. 1

Status
Not open for further replies.

stephenlecomptejr

Programmer
Jun 3, 2003
3
US
If I have a form that I want to display the results of a query after I click a command button - what codes do I need to type under the _Click command? I asked this question in another forum and they said that I need to establish a display control and used an example of a recordset. But they wouldn't explain how to make my recordset pull from the query!

qrySearch is the name of my query. The criteria listed in this query is based off of [Forms]![frmSearch]![txtSearch]
After I type the info in txtSearch and press the click button on Go, I want the form to display the results of that query. Thanks for all your help - hope you can help me out?
 
Put the following code in your buttons On Click event:

DoCmd.OpenQuery "qrysearch", acNormal
 
Open your query in design mode and put your code: [Forms]![frmSearch]![txtSearch] in the criteria of the field you want to filter out.

On the on-click even of the button open your form and make sure your form recordsource is set as qrySearch.

Done.

:)WB
 
If you don't need a fancy form to display the query results, simply use the OpenQuery statement. For example:
Code:
Private Sub btnGo_Click()
  On Error Resume Next
  DoCmd.OpenQuery "qrySearch", acViewNormal, acReadOnly
End Sub
Leave off the acReadOnly parameter if you want to allow the user to edit the data displayed.

If you do want a custom form, then you could use one of the AutoForm wizards to design a form to display instead of the plain query. For example, assuming the AutoForm wizard built a form named "frmSearch" using "qrySearch" as its record source:
Code:
Private Sub btnGo_Click()
  On Error Resume Next
  DoCmd.OpenForm "frmSearch", acNormal, , , acFormReadOnly, acDialog
End Sub
Leave off the acDialog parameter if you want to allow the user to leave the query results form open, otherwise the user is required to close the form before continuing with other work.

Leave off the acFormReadOnly parameter if you want to allow the user to edit the data displayed.
 
Thanks for your replies. I appreciate it...
But this form (frmSearch) is an input screen (with txtSearch as the input data) as well as displaying the resulting search data (qrySearch).

So instead of opening a new form or a new query - I would like to display the query results on the form itself. When someone types in another search criteria - I want the same form (not a new one) to display the new results of the query. Please help me.
 
You can add a subform to your search form. Set the subforms data source to your query. Then add the following code to your search forms OnLoad event:

Forms!frmSearch!NameOfSubForm.Visible = False

Add the following code to your search form button:

Forms!frmSearch!NameOfSubForm.Visible = True
Me.Requery

This will open your search form with the imbedded subform hidden. Once the search form button is pressed, it will show your imbedded subform and requery the data for the fresh results.

Hope this makes sense.
 
This problem was solved using this code under the click command:

Me.Recordsource = "qrySearch"
Me.Requery

Thanks for the help, tho.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top