![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
| When a button is clicked on a Access Form, I want to run a query and display its result. I am able to do that, but my form has 12 buttons and I am creating 12 different query objects(containing the 12 queries) for them. So, the left had side of my window(which displays all Access objects) which shows 12 query objects. Now, I have to create another form which has 6 buttons which on clicked will run 6 different queries. 1. Is there a way in Access 2007 where instead of creating another 6 query objects I can create a single query object which can contain the 6 different queries and run query 1 when button 1 is clicked, run query 2 when button 2 is clicked and so on. 2. If there is no such way, can I alleviate the issue of having multiple query objects by running a macro when the button is clicked which runs a query based on which button is clicked and produces the results. How difficult would this be to do? Currently, all I have to do is create a query object and add some SQL to it so that it produces the desired result. Any suggestions would be appreciated. |
#3
| |||
| |||
|
| When a button is clicked on a Access Form, I want to run a query and display its result. I am able to do that, but my form has 12 buttons and I am creating 12 different query objects(containing the 12 queries) for them. So, the left had side of my window(which displays all Access objects) which shows 12 query objects. Now, I have to create another form which has 6 buttons which on clicked will run 6 different queries. 1. Is there a way in Access 2007 where instead of creating another 6 query objects I can create a single query object which can contain the 6 different queries and run query 1 when button 1 is clicked, run query 2 when button 2 is clicked and so on. 2. If there is no such way, can I alleviate the issue of having multiple query objects by running a macro when the button is clicked which runs a query based on which button is clicked and produces the results. How difficult would this be to do? Currently, all I have to do is create a query object and add some SQL to it so that it produces the desired result. Any suggestions would be appreciated. |
#4
| |||
| |||
|
|
g wrote: When a button is clicked on a Access Form, I want to run a query and display its result. I am able to do that, but my form has 12 buttons and I am creating 12 different query objects(containing the 12 queries) for them. So, the left had side of my window(which displays all Access objects) which shows 12 query objects. Now, I have to create another form which has 6 buttons which on clicked will run 6 different queries. 1. Is there a way in Access 2007 where instead of creating another 6 query objects I can create a single query object which can contain the 6 different queries and run query 1 when button 1 is clicked, run query 2 when button 2 is clicked and so on. 2. If there is no such way, can I alleviate the issue of having multiple query objects by running a macro when the button is clicked which runs a query based on which button is clicked and produces the results. How difficult would this be to do? Currently, all I have to do is create a query object and add some SQL to it so that it produces the desired result. Any suggestions would be appreciated. Here's an example of two command buttons running different SQL statements using the same query. Option Compare Database Option Explicit Function IsQueryOpen(strname As String) As Boolean 'see if query is already open If SysCmd(acSysCmdGetObjectState, acQuery, strname) <> 0 Then IsQueryOpen = True End If End Function Private Sub CloseQuery() 'close TempQ query if open and delete it if it exists. On Error Resume Next If IsQueryOpen("TempQ") Then DoCmd.Close acQuery, "TempQ" End If DoCmd.DeleteObject acQuery, "TempQ" End Sub Private Sub CommandCustomers_Click() 'customers command button CloseQuery Dim qdf As QueryDef Set qdf = CurrentDb.CreateQueryDef("TempQ", "Select * From Customers") DoCmd.OpenQuery "TempQ" DoCmd.SelectObject acQuery, "TempQ" End Sub Private Sub CommandContacts_Click() 'contacts command button CloseQuery Dim qdf As QueryDef Set qdf = CurrentDb.CreateQueryDef("TempQ", "Select * From Contacts") DoCmd.OpenQuery "TempQ" DoCmd.SelectObject acQuery, "TempQ" End Sub |
#5
| |||
| |||
|
|
It sounds like you are saying you are using up screen space to place one button for each query. If so, plan on getting a bigger screen! As soon as you add more queries, you'd need more buttons, right?! |
|
Here's an alternate approach, in the way of an analogy... I have an application with several dozen reports. Rather than put each report behind a button on a "reports" form, I use a combobox to list the reports. After the user selects a report, s/he clicks the<Print Preview button (only one button). Behind that button, I have code that runs the OpenReport command, using the selected report in the combobox as the parameter in the command that calls for the name of the report to open. I wonder if you could do something similar? |
![]() |
| Thread Tools | |
| Display Modes | |
| |