467,858 Members | 1,699 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,858 developers. It's quick & easy.

VBA Form Filter being ignored.

GazMathias
Expert 100+
Hi Guys,

Acc2003.

I have a form that is misbehaving by suddenly refusing to apply a filter I am passing to it.

In a nutshell, I use a public variable to control the form's behaviour called gstrAction.

I have a listbox on the preceding form containing record summaries that I use to open the new form with two buttons:

bttnNew sets gstrAction to "New" and opens the form in acFormAdd mode.

bttnEdit sets gstrAction to "Edit" and passes the filter.

Expand|Select|Wrap|Line Numbers
  1. "[SampleID] = " & Me.lstSample
  2.  
However, the form continues to open in New mode.

If I MsgBox on form open the values gstrAction, Me.Filter and Me.FilterOn they are all as one would expect.

Strangely, If I go into design mode and back the filter is applied!

I have compiled my code, compact and repaired and created a new .mdb and imported all of the objects. Still the same behaviour.

I have circumvented this behaviour temporarily by not passing the filter in but rather have the form check if it is in "Edit" mode on open. If it is it grabs the Selected Index off of the list form and applies the filter itself.

However, this is now playing havoc with some of the form's other functions, for example there is code that dictates what the buttons' captions display and what they do based on populated data and mode.


Any ideas how I can get the filter working?


Gaz.
Aug 27 '09 #1

✓ answered by ajalwaysus

What happens if after you open the form, you set a requery of the form, perhaps it's just the order in which this is happening which is bizarre, considering it did work before.
I say try a delayed requery of the form, since when you put the form in design view and back it is working.

-AJ

  • viewed: 2995
Share:
9 Replies
FishVal
Expert 2GB
@GazMathias
Hello, Gaz.

Just a thought.
Could it be so that you somewhere change AllowAdditions and/or DataEntry property of the form at runtime and then, after reopening through design mode, form gets values of those properties saved in form object?

Regards,
Fish.
Aug 27 '09 #2
GazMathias
Expert 100+
@FishVal

Hi Fish,

Unfortunately not. Both are True on open when using the [SampleID]= method, and when going into design mode and back, and using my temporary fix.

Gaz.
Aug 27 '09 #3
Expert 1GB
How about just passing OpenArgs to the form and having it set its own filter appropriately?
Aug 27 '09 #4
GazMathias
Expert 100+
@ChipR
That is essentially what I am doing with the fix, though I am grabbing the Sample_ID directly off the preceding form. Again, this method does apply the filter, but messes with the custom button behaviour.

I'm sorely tempted to just recreate the form from scratch. Just so bizarre that it's stopped working.

Should've mentioned, other parts of the app use this type of list-form, detail-form relationship and they still work.

Gaz.
Aug 27 '09 #5
Expert 100+
What happens if after you open the form, you set a requery of the form, perhaps it's just the order in which this is happening which is bizarre, considering it did work before.
I say try a delayed requery of the form, since when you put the form in design view and back it is working.

-AJ
Aug 27 '09 #6
GazMathias
Expert 100+
@ajalwaysus
Hi,

I set the timer interval to 10, and in the event requeried and refreshed the form, turned the timer off and called my button management code and it now works pretty much as it used to, so thanks for the suggestion.

Could the underlying cause of this be that something is awry in one of the system tables? Is there a tool that can be run to verify their integrity?

Otherwise, solved : )

Gaz
Aug 27 '09 #7
Expert 100+
I'm not sure, I am not an expert of these issues, I just know I have them as well, and have learned to do workaround for the short term. =)

As an add on to the delayed requery, you may want to write code in VBA to set the timer on the form load or open event and then set it to zero after the timer has executed once, so you are not requerying every 10 milliseconds.

I also wonder if a DoEvents line somewhere in the form load or form open would take care of this, it just seems like there is something running in the background that needs to finish before the filter is applied.

-AJ
Aug 27 '09 #8
GazMathias
Expert 100+
@ajalwaysus
That is exactly what I did, but only if gstrAction = "Edit".

Gaz.
Aug 27 '09 #9
NeoPa
Expert Mod 16PB
@GazMathias
Gaz,

I would tend to use OpenArgs where necessary, but for filtering required at call time (rather than a changing requirement after the form's been opened) I would pass it in the call itself.

Where the value is passed though (whether by gstr or OpenArgs), I would expect a .Requery to be required as soon as the .Filter... properties have been set. I don't see a need for Timer code here (though I'm open to correction).

I've used global variables in the past, but I find I'm moving away from them where possible nowadays. Very few examples left now (in my code).
Aug 31 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Robert Neville | last post: by
reply views Thread by CSDunn | last post: by
2 posts views Thread by Andante.in.Blue | last post: by
9 posts views Thread by Brendan MAther | last post: by
2 posts views Thread by misschristalee | last post: by
2 posts views Thread by cefrancke | last post: by
5 posts views Thread by Thelma Roslyn Lubkin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.