UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Filter problem    
 
   
MrSiezen
post Sep 15 2005, 08:37 AM
Post #1

UtterAccess Ruler
Posts: 2,196
From: Den Bosch - Netherlands



Hi! I'm having problems applying a filter.

I have a command button which applies this simple filter:

Code:
--------------------------------------------------------------------------------

Me.Filter = "[Status] = 'WC'"
--------------------------------------------------------------------------------


But now I discovered that this filter didn't do enough. I need to exclude some more records. I need to exclude record which have a certain branchecode (which is a control on the form). Those certain codes are ("black-")listed in a query (which is dynamic, so I can't just enter those codes into the filter).

So what I need the filter to do besides the earlier posted one, is exclude a record if it's branchecode is equal to ANY of the branchecodes from the query.

If I'm not clear enough yet, just ask!
Go to the top of the page
 
+
HelloAgain
post Sep 15 2005, 12:56 PM
Post #2

UtterAccess Guru
Posts: 703



However you are generating the value in the branchcode control on the form you will have to generate in the query. How are you generating the value on the form? Using some formula entered in the expression builder?
Go to the top of the page
 
+
MrSiezen
post Sep 16 2005, 03:55 AM
Post #3

UtterAccess Ruler
Posts: 2,196
From: Den Bosch - Netherlands



I'm not really sure what you mean.

I'm not generating the value on the form, I'm generating the values in a query.

This query uses a criteria from the form, so it's dependant on which record is opened in the form.

I'll explain it with a example:

The form is open and the command for the filter is clicked. The criteria value for the query is found in the control Me!Network (e.g. '31012')

What should happen:
The filter must use the values of the query ('qryFilter'), so let's open it. This query calculates which branches are 'occupied' in this network '31012'. This means that it generates a list of (about 25) branches which shouldn't be shown on the form. Let's say these values are 0403, 0404, 0605, 0606, ...

So, along with the earlier mentioned filter Me.Filter = "[Status] = 'WC'" :


Me.Filter = "[Status] = 'WC' AND Me.Branchecode NOT IN (0403, 0404, 0605, 0606, ...)" (Didn't test this code btw)

But how can I keep this filter dynamic? So how can I let these values recalculted every time with the query?
Go to the top of the page
 
+
datAdrenaline
post Sep 17 2005, 02:44 AM
Post #4

UtterAccess Editor
Posts: 15,965
From: Northern Virginia, USA



Instead of using the Filter property, you may want to consider making the forms recordsource an SQL statement, then modifying the SQL statement programatically ...

In the code that currently sets the filter ....

Const cstrSQL as String = "Select tblMyTable.* FROM tblMyTable" 'The RAW, Unfiltered SQL Statement
strSQL As String 'The SQL statement for the recordsource
.
.
strSQL = cstrSQL & " WHERE [Status]='WC' And Me.Branchcode Not In (SELECT BranchCode FROM qryOfRestrictedCodes)"

Me.Recordsource = strSQL
.
.
.

Setting the Recordsource property will automatically cause Access to Requery the form, then Access will take care of running the qryOfRestrictedCodes when the form is requeried.

Another benifit to setting the recordsource is the fact that It is typically faster than filtering.

HTH ...
Go to the top of the page
 
+
mishej
post Sep 17 2005, 02:50 AM
Post #5

Retired Moderator
Posts: 11,289
From: Milwaukee, WI



Make sure you also set the .FilterOn property:

Me.FilterOn = True
Go to the top of the page
 
+
MrSiezen
post Sep 20 2005, 02:52 AM
Post #6

UtterAccess Ruler
Posts: 2,196
From: Den Bosch - Netherlands



Alrighty!

Sorry I didn't reply earlier, but we're having a hard time syncronising our new interactive website with my Access database.

Taking a little breather from that now, and I tried what you explained to me.

I didn't do exactly what you suggested, but I'm hesitating a bit to change the recordset. It's quite a complicated database system, with all kinds off logging and tracing functions. One of the basics for that is that users are restricted to a recordset, unless they change it by a predefined procedure.

So I sicked to the filter, but I got this to work perfectly:

Me.Filter = "[TblData]![Status] ='WC' And [TblData]![Branchecode] In (SELECT Branchecode FROM VrijBrnetwerkbranchesLijst)"
Me.FilterOn = True


Thank you guys for helping me out with this! (IMG:http://www.utteraccess.com/forum/style_emoticons/default/yayhandclap.gif)
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th May 2013 - 03:38 PM