How do I populate fields in a form from a query?

G

Guest

I have a switchboard and two other forms. The first form, acronym, has a
textbox that is the control source for a query. The result(s) of the query
is/are the control source for a new form, results, that opens displaying two
fields. On the results form, I have a textbox that is the control source for
the same query mentioned above, but I cannot get the results to stay on the
results form. Basically, I want users to click on the first form "Run"
command for the query, opens the results form, and then they can run the
query as many times as necessary and have the results stay in the results
form. Thanks.
 
L

Larry Linson

Your use, to mean something different, of terms with specific meaning in
Access makes your question difficult for Access people to follow.

A query does not have a "Control Source". Controls have a Control Source,
which is a Field in the RecordSource of the Form, or a calculated value.
Forms have a RecordSource, which can be a Table, a Query, or an SQL
Statement.

And, I just don't understand what you mean by "cannot get the results to
stay on the results form".

If you make the Query the RecordSource of the "results form", and use
appropriate fields as the Control Source of Controls, the results should
display there until you change the Query that is the RecordSource.

If you want multiple copies of the same form to be open, then you will have
to instantiate them from VBA code.

Larry Linson
Microsoft Access MVP
 
G

Guest

Let me try again. My main form has a textbox that a user would input text to
search for. The query that runs uses the text from that textbox as its
criteria and opens a new form displaying the result(s), which is what I want
to happen. On the form with the results, I want to have the same kind of
setup, a textbox, that a user can enter text to search on and run the same
query as above. But instead of opening a new form, I want the results
displayed in the same form, results, above the textbox the user typed in
text. Right now when I run the query from the results form, not the main
form, I can set it up to open yet another form or a datasheet view displaying
the results. I am trying to word this the best I can.

When in the "results" form and the run command is clicked calling my query,
here is what happens:

"Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

Dim stDocName As String

stDocName = "acronym"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub"

How do I get the results to stay on the form instead of opening a datasheet
view? Thanks.

Mac
 
R

Ron2005

You should not openquery.

Instead simply have the third form on the second form and have the
onupdate event of the second form issue a me.subform3name.requery. (or
have it be in place of the openquery command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top