First, build a Query for the universe of data that can be seen by the
user --- all fields from all related tables (even fields that you may not
want displayed but which you may need access to in the code behind the form.
Second, create a Form with unbound controls representing the various data
fields the users can query against and other questions you want them to
answer that affect the result. Set the RecordSource of this Form to the
Query you built, and set AllowEdits=Yes, DataEntry=No, AllowDeletions=No,
AllowFilters=Yes, AllowAdditions=No. You'll need AllowEdits=Yes to allow
the user to merely enter data into the form --- this doesn't mean the user
will actually be able to change the data in the tables because the fields
used to display the data will be locked,
Third, put a button on this Form, and create an OnClick event for the
button. In the OnClick event, put code to examine all the various conotrols
where the user may have entered data on the form. From this, build an SQL
filter (basically, an SQL WHERE clause without the word "WHERE" at the
beginning). You may need to build this piece by piece with appropriate AND
clauses, etc. Put the whole thing together into a string variable (such as
strFilter).
Next within the OnClick event, set the filter by executing the following:
DoCmd.AppyFilter , strFilter
[and note the presence of the comma as the SQL you built is the second
parameter, the first being absent]
Immedately following this, tell Access to requery the data behind the form:
Me.Requery
The records now available to the Form are only those that meet the
characteristics of the filter.
You'll need locked/disabled controls on the form for actually displaying the
result. The user can then scroll through the result.
Bob.
evanda said:
I'd like to use a form merely for allowing people to look up information.
they'd enter a value, and various queries could be executed from their input
and various values reported. I don't want them adding anything, just
entering bits to be used in the query.