A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Change an underlying query paramaters by button on a form



 
 
Thread Tools Display Modes
  #1  
Old January 27th, 2010, 01:49 AM posted to microsoft.public.access.forms
GLT
external usenet poster
 
Posts: 154
Default Change an underlying query paramaters by button on a form

Hi,

I have a form that is bound to a query. The form displays a list of servers
and a count of errors that have occured on each server.

I also have two buttons on my form, one which is labelled 'All' and the
other is labelled 'Errors Only'.

I have modified the query (via the QBE grid) to allow for both situations,
and copied the SQL as follows:

When I click the 'All' button, I would like the following SQL to run:

SELECT Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, Abs(Sum(Services.Valid)) AS ErrorCount,
IIf([Ping]=-1,"OK","FAIL") AS PingRslt
FROM Full_Compare_Q LEFT JOIN Services ON Full_Compare_Q.RecID =
Services.RecID
GROUP BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, IIf([Ping]=-1,"OK","FAIL")
ORDER BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server;

When I click the 'Errors Only' button, I would like the following SQL to run:

SELECT Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, Abs(Sum(Services.Valid)) AS ErrorCount,
IIf([Ping]=-1,"OK","FAIL") AS PingRslt
FROM Full_Compare_Q LEFT JOIN Services ON Full_Compare_Q.RecID =
Services.RecID
GROUP BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, IIf([Ping]=-1,"OK","FAIL")
HAVING (((Abs(Sum([Services].[Valid])))1)) OR
(((IIf([Ping]=-1,"OK","FAIL")) Like "FAIL"))
ORDER BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server;

These two lots of SQL work fine, I just want to be able to change the Query
parameters when either button is clicked. Can anyone advise how to do this?

Any help is always greatly appreciated...

Cheers,
GLT.
  #2  
Old January 27th, 2010, 05:39 AM posted to microsoft.public.access.forms
Tom van Stiphout[_2_]
external usenet poster
 
Posts: 1,653
Default Change an underlying query paramaters by button on a form

On Tue, 26 Jan 2010 17:49:01 -0800, GLT
wrote:

I have my doubts about your use of the Having clause vs the Where
clause, but that aside:
Create two queries, each with their sql statement. Note that you can
create a new query, switch to sql view, and paste in your statement.
Say you named them q1 and q2.
Then in the All-button's click event write:
Me.RecordSource = "q1"
I'm sure you can figure out what to write in the other button's Click
event :-)

-Tom.
Microsoft Access MVP


Hi,

I have a form that is bound to a query. The form displays a list of servers
and a count of errors that have occured on each server.

I also have two buttons on my form, one which is labelled 'All' and the
other is labelled 'Errors Only'.

I have modified the query (via the QBE grid) to allow for both situations,
and copied the SQL as follows:

When I click the 'All' button, I would like the following SQL to run:

SELECT Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, Abs(Sum(Services.Valid)) AS ErrorCount,
IIf([Ping]=-1,"OK","FAIL") AS PingRslt
FROM Full_Compare_Q LEFT JOIN Services ON Full_Compare_Q.RecID =
Services.RecID
GROUP BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, IIf([Ping]=-1,"OK","FAIL")
ORDER BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server;

When I click the 'Errors Only' button, I would like the following SQL to run:

SELECT Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, Abs(Sum(Services.Valid)) AS ErrorCount,
IIf([Ping]=-1,"OK","FAIL") AS PingRslt
FROM Full_Compare_Q LEFT JOIN Services ON Full_Compare_Q.RecID =
Services.RecID
GROUP BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, IIf([Ping]=-1,"OK","FAIL")
HAVING (((Abs(Sum([Services].[Valid])))1)) OR
(((IIf([Ping]=-1,"OK","FAIL")) Like "FAIL"))
ORDER BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server;

These two lots of SQL work fine, I just want to be able to change the Query
parameters when either button is clicked. Can anyone advise how to do this?

Any help is always greatly appreciated...

Cheers,
GLT.

  #3  
Old January 27th, 2010, 02:37 PM posted to microsoft.public.access.forms
GLT
external usenet poster
 
Posts: 154
Default Change an underlying query paramaters by button on a form

Hi Tom,

Thanks for your reply... thats what I wound up doing, is creating two
seperate queries and when each button is clicked, it chagnes the recordset
source to the corresponding query. Works great...

Cheers,
GLT

"Tom van Stiphout" wrote:

On Tue, 26 Jan 2010 17:49:01 -0800, GLT
wrote:

I have my doubts about your use of the Having clause vs the Where
clause, but that aside:
Create two queries, each with their sql statement. Note that you can
create a new query, switch to sql view, and paste in your statement.
Say you named them q1 and q2.
Then in the All-button's click event write:
Me.RecordSource = "q1"
I'm sure you can figure out what to write in the other button's Click
event :-)

-Tom.
Microsoft Access MVP


Hi,

I have a form that is bound to a query. The form displays a list of servers
and a count of errors that have occured on each server.

I also have two buttons on my form, one which is labelled 'All' and the
other is labelled 'Errors Only'.

I have modified the query (via the QBE grid) to allow for both situations,
and copied the SQL as follows:

When I click the 'All' button, I would like the following SQL to run:

SELECT Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, Abs(Sum(Services.Valid)) AS ErrorCount,
IIf([Ping]=-1,"OK","FAIL") AS PingRslt
FROM Full_Compare_Q LEFT JOIN Services ON Full_Compare_Q.RecID =
Services.RecID
GROUP BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, IIf([Ping]=-1,"OK","FAIL")
ORDER BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server;

When I click the 'Errors Only' button, I would like the following SQL to run:

SELECT Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, Abs(Sum(Services.Valid)) AS ErrorCount,
IIf([Ping]=-1,"OK","FAIL") AS PingRslt
FROM Full_Compare_Q LEFT JOIN Services ON Full_Compare_Q.RecID =
Services.RecID
GROUP BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server,
Full_Compare_Q.RecID, IIf([Ping]=-1,"OK","FAIL")
HAVING (((Abs(Sum([Services].[Valid])))1)) OR
(((IIf([Ping]=-1,"OK","FAIL")) Like "FAIL"))
ORDER BY Full_Compare_Q.BTSContactGroup, Full_Compare_Q.Server;

These two lots of SQL work fine, I just want to be able to change the Query
parameters when either button is clicked. Can anyone advise how to do this?

Any help is always greatly appreciated...

Cheers,
GLT.

.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:25 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.