How to run multiple queries with one button in Microsoft Access?

Anonymous
2025-03-25T20:28:54+00:00

Hello all,

I have a search form with a search button that runs a query on a table. You can search for number ID, year, and name. The search button opens another form that matches what was typed in the search form. The second form that opens up displays more information about the record that was searched for. I would like to be able to search for multiple records at the same time from the same table. My search form only opens up one record at a time and I would like to open 2-3 records and their information to compare them. If I type in a new record in the search form while the resuIt form from the previous search is open, the new search just replaces the previous result.

I tried creating other search boxes and buttons in the same form, but the results only replace the results from the first search from the first search boxes.

I am fairly new to access and anything would be helpful. Would I need to create another button or is it even possible to run queries at the same time? Is trying to use 2 queries on the same table the problem?

Microsoft 365 and Office | Access | Other | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2025-03-25T21:46:45+00:00

    There is no need to use multiple queries.  You can use a single query as the RecordSource property of the second form, and include multiple parameters in it to restrict the records returned in the form.

    You might like to take a look at DatabaseBasics.zip in my Dropbox public databases folder at:

    https://www.dropbox.com/scl/fo/0scigd3r48hx5xrev2jrf/AB0-GMdTgMAO5O1cGdr3QW0?rlkey=ib6bs6g9jqcrywwzivur3265t&dl=0

    In this little demo file the first form in the section on 'retrieving data from the database' includes three unbound subforms illustrating different types od searches.  That on the right allows you to select up to two parameters in combo boxes, but it could easily be extended to include more controls for entering/selecting other parameters.

    In the demo a report is opened to return the results, but a form can be opened in exactly the same way.  The report's RecordSource is the following query which references the two combo boxes in the subform:

    SELECT [FirstName] && " " && [LastName] AS FullName, Address, City, Region,
    
    Country, Employer, LastName, FirstName, Contacts.ContactID
    
    FROM (Countries INNER JOIN Regions ON Countries.CountryID = Regions.CountryID)
    
    INNER JOIN (Employers INNER JOIN ((Cities INNER JOIN Contacts
    
    ON Cities.CityID = Contacts.CityID) INNER JOIN ContactEmployers
    
    ON Contacts.ContactID = ContactEmployers.ContactID)
    
    ON Employers.EmployerID = ContactEmployers.EmployerID)
    
    ON Regions.RegionID = Cities.RegionID
    
    WHERE (Cities.CityID = Forms!frmReportDialogue!cboCity
    
      OR Forms!frmReportDialogue!cboCity IS NULL)
    
    AND (Employers.EmployerID = Forms!frmReportDialogue!cboEmployer
    
      OR Forms!frmReportDialogue!cboEmployer IS NULL);
    

    By examining the parameters for OR IS NULL this allows the user to enter/select values in as few or as many of the controls in the subform as necessary.  The option for combining the parameters with AND or OR is given.  The above query uses the AND operator, so those rows which match both parameters are returned.  If the OR option is selected rows which match either of the parameters would be returned.

    The other subforms in the same form in the demo illustrate two methods for using a multi-select list box to restrict the results by multiple values in the same column (field).

    0 comments No comments
  2. ScottGem 68,755 Reputation points Volunteer Moderator
    2025-03-26T11:40:13+00:00

    Does the query return multiple records or only one? If the query returns multiple records then opening a form bound to the query will display multiple records. A form can be viewed in different ways. The default view is single record view where you view one record at a time. But there should be a navigation bar at the bottom which will indicate how many records have been returned and allow you to navigate between the records.

    Or you can create a continuous form which will display multiple records in rows. You can also view the form in datasheet view which is like viewing the table or query directly.

    Another option to explore is using a Split form. This allows you to view the form in Single view AND datasheet view simultaneously. This also allows you to use datasheet filtering in the datasheet view portion to further filter the records returned.

    0 comments No comments