Populate a form based on a query using parameters

  • Thread starter Thread starter Mommybear
  • Start date Start date
M

Mommybear

I have created a form that is populated from a query. I have a text box set
up as an input box and click a button (Search) to execute the search. This
appears to be working fine as the query opens and runs. However, it displays
in the query in data format instead of in the Form I created. How do I get
this information to populate the form, not the actual query. The Search
button is set to RunQuery.
 
I have created a form that is populated from a query.  I have a text box set
up as an input box and click a button (Search) to execute the search.  This
appears to be working fine as the query opens and runs.  However, it displays
in the query in data format instead of in the Form I created.  How do Iget
this information to populate the form, not the actual query.  The Search
button is set to RunQuery.

If I understand you correctly, you have based the form on the query ie
the form displays the data returned by the query. If so, use a combo
box on the form (when you drop the combo control on the form, the
wizard will guide you). This will take you to the record you want
 
There are multiple records that can be returned. Here is an example.

Type Name Location New
A camera 1st floor 1
B camera 2nd floor 0
A camera 3rd floor 1

My input is to query on the Type and return all records with that type:
Input = 'A' should return on the Form:
Type Location New
A 1st floor 1
A 3rd floor 1

I have hundreds of types, therefore a Combo box would not work.
 
Mommybear -

RunQuery will open a query, which is not what you want. What you want is
for this query to be the recordsource for the form. Then if you change this,
you just need to do a Me.Requery.
 
It is my recordsource. I just don't know how to get the data to appear on
the form. What is a Me.Requery and where do I add this. I'm sorry, I'm
really not that familiar with Access.
 
Mommybear -

My understanding is your form is populated when you open it. Then you enter
something into a text box and click the Search button and expect the form to
now contain records based on the search criteria. If this is the case, then
in your Search button, instead of RunQuery (which will open a query in
datasheet mode in a new window), you want to re-query what is displayed in
the form based on the record source for the form. In that case, add this
code in your click event of the search button:
Me.Requery
That will cause the records on the form to be refreshed from the database
based on the current record source.

If your form is not populating at all, then make sure the controls (text
boxes, etc.) are bound to fields in the record source (the Control Source
property for each control has a field name from the query).

If you are using a main form with a subform, then let us know, as that would
mean a different answer. If this posting doesn't help, please be more
specific about what you are changing (what does the Search button do), and
what is not working...
 
My form is populated when I open it, which I really don't want it to do. I'm
just working on one problem at a time. I want it to open to a blank screen,
the user will enter the code they want to see, hit the search button, then
have the query run and the data populate. My data could be anywhere from 1+
lines so I have a header that is set up to list the info that is the same on
each record such as the code that is being searched, the item description and
category. The remaining data will display in the detail section as it defers
for each record such as location.
 
OK, so did you put in the Me.Requery in the code behind the search button?
That should do what you want.
 
Back
Top