dbTalk Databases Forums  

Using Global Variables In Query With IIF

comp.databases.ms-access comp.databases.ms-access


Discuss Using Global Variables In Query With IIF in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bezz
 
Posts: n/a

Default Using Global Variables In Query With IIF - 01-03-2011 , 11:57 AM






I have a query which filters defects by a system code. The collation of defects by system is achieved by setting a system variable using a form so that it is held as a global
variable.

I then filter the query using GetSystemID() as a criteria in the query, bringing up all defects associated with that system.

A further requirement is to then recognise which of those defects have been prioritised and identify them. THis is done by allocating a code within a priority field.

For example "ST" as an event code. What I wish to do is if the priority code contains "ST" then add the letters "-ST" to the defect number to signify it has priority. It would be
simple to just filter for ST I know, but I want to make this a routine that can be used for any priority defects with different codes such as "L", "CFG" or any combination.

I have created a form which allows the user to set the current priorities he is interested in and this stores the currently required code in a Global Variable called
GBLKeyeventTIPCode a string variable

I can use this to filter specific defects using a Public Sub:

Public Function GetTIPCodeVariable()
GetTIPCodeVariable = GBLKeyeventTIPCode
End Function

This is used in a query with the criteria in the query - GetTIPCodeVariable()

I am aware you cannot use Global Variables directly in Queries, but it would be useful to be able to identify from the number of defects which ones were priority by using the
following type of statement such as:

NCSPECIFIC: IIf([NC_PRIORITY]=GetTIPCodeVariable(),[NCNUMBER] & GetTIPCodeVariable(),[NCNUMBER])

such that if the priority code matches the desired event, it adds it to the defect number, otherwise the defect number stays as is, so you would have for example:

34567ST
34568
34569
24574ST

So the priorities are marked. Anyone have any examples of using a Global as a comparison inside a query like this?

Thanks

J



--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Using Global Variables In Query With IIF - 01-03-2011 , 01:06 PM






bezz wrote:

Quote:
I have a query which filters defects by a system code. The collation of defects by system is achieved by setting a system variable using a form so that it is held as a global
variable.

I then filter the query using GetSystemID() as a criteria in the query, bringing up all defects associated with that system.

A further requirement is to then recognise which of those defects have been prioritised and identify them. THis is done by allocating a code within a priority field.

For example "ST" as an event code. What I wish to do is if the priority code contains "ST" then add the letters "-ST" to the defect number to signify it has priority. It would be
simple to just filter for ST I know, but I want to make this a routine that can be used for any priority defects with different codes such as "L", "CFG" or any combination.

I have created a form which allows the user to set the current priorities he is interested in and this stores the currently required code in a Global Variable called
GBLKeyeventTIPCode a string variable

I can use this to filter specific defects using a Public Sub:

Public Function GetTIPCodeVariable()
GetTIPCodeVariable = GBLKeyeventTIPCode
End Function

This is used in a query with the criteria in the query - GetTIPCodeVariable()

I am aware you cannot use Global Variables directly in Queries, but it would be useful to be able to identify from the number of defects which ones were priority by using the
following type of statement such as:

NCSPECIFIC: IIf([NC_PRIORITY]=GetTIPCodeVariable(),[NCNUMBER] & GetTIPCodeVariable(),[NCNUMBER])

such that if the priority code matches the desired event, it adds it to the defect number, otherwise the defect number stays as is, so you would have for example:

34567ST
34568
34569
24574ST

So the priorities are marked. Anyone have any examples of using a Global as a comparison inside a query like this?

Thanks

J

If I understand your issue (I may not) you could create a hidden field
on a form. Call it GlobKey. Then sometime assign a value to GlobKey;
maybe in the OnLoad or OnCurrent event. Now if the form's name is
TestForm, you can reference the value with
Forms!TestForm!GlobKey

Reply With Quote
  #3  
Old   
bezz
 
Posts: n/a

Default Re: Using Global Variables In Query With IIF - 01-03-2011 , 02:06 PM



I know I could do it with a text box on an open form, but I was trying to get away from that as the global is used across several different forms and reports generated from the query.

The global is set using a combo box which populates a text box, and updates the global variable as required using the after update property of the combo. The intention is to use the
form to set the key event on startup and have it as the default avsilable to any part of the database of possible.

Regards

JBN


--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Reply With Quote
  #4  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Using Global Variables In Query With IIF - 01-03-2011 , 02:28 PM



bezz wrote:
Quote:
I am aware you cannot use Global Variables directly in Queries, but
it would be useful to be able to identify from the number of defects
which ones were priority by using the following type of statement
such as:

NCSPECIFIC: IIf([NC_PRIORITY]=GetTIPCodeVariable(),[NCNUMBER] &
GetTIPCodeVariable() ,[NCNUMBER])

Have you tried this? It looks to me as if it should work.
Anyways, why call the function twice? This would do the same thing, wouldn't
it?

NCSPECIFIC: IIf([NC_PRIORITY]=GetTIPCodeVariable(),[NCNUMBER] &
[NC_PRIORITY],[NCNUMBER])

I just tested and it did exactly what you want.

Reply With Quote
  #5  
Old   
bezz
 
Posts: n/a

Default Re: Using Global Variables In Query With IIF - 01-03-2011 , 03:29 PM



Bob,

Many thanks, it does work as you say, and your tweak removes the requirement to call the function twice. I have stuck in a &" - " & to make it clearer but this works fine.

Thanks very much for your assistance.

J


--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.