Listen for Table Filter Activation - vba

I have a table that has a series of filters across the top of it (as per usual.) This table feeds a massive graph that has multiple series of data in it. In order to hide different series of data I have grouped the information in the tables. I can then click on the minus button to remove a series of data from the graph by collapsing the group, or click the plus button to add it back in the same way. Yes, I know, not the best solution. It was an early effort, what can I say? My default is for all data to be hidden (all groups collapsed).
I have a user (a very important user) who wants to be able to use the filters across the top to find the specific series they are looking for. The filter will find the collapsed series just fine, but the series will not display because it is collapsed.
So, What I'm trying to do is get all groups to auto-expand when the filter is activated. This should work as a stop gap measure until I can simply redesign the chart.
The Problem: I can't figure out how to make Excel notice when the filter has been clicked on (or otherwise used). I've tried using Worksheet_Change and Worksheet_SelectionChange, but neither of them activate the code I have set up in the listener. That code, FYI, checks to make sure the filter is in use and adjusts the groupings accordingly. It should work fine if I can just get Excel to notice it's existence.
I've looked into making my own listener, but there's nowhere in the code I can insert it to make it activate. I just need a listener that will notice when the filter has been changed.
Any thoughts? After an hour of searching I'm stumped...

Okay, after some research I figured out a work around. The big problem here is that changing a filter does not raise any events that can be heard by VBA. Big problem.
Simple Solution: Create something that will activate a listener.
What I ended up doing was finding a cell somewhere outside of my table that wasn't going to be affected by the collapses, then I added a very simple formula (=Count(H:H)). Now whenever the table is collapsed the count is affected which activates the Worksheet_Calculate listener. And voila! I can dynamically change the groupings all I want :-).
So there you have it. If you need to detect a filter being activated via a Worksheet listener, you just need to set up a formula to activate the calculate listener.
Reference: [MSDN Article on the same thing].1 There is apparently a much more robust way to fix this problem as well which is detailed in the article.

You mentioned table, so assuming it's PivotTable you may try,
Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
If it's simply a Targe Range change then,
If Intersect(Target, Range("A2"))

Related

How to modify an output value in LabVIEW?

I am very new to LabVIEW and what I want is to know if it's possible to modify an indicator. I have a loop, and in every iteration I want to add a new value (given by the user via a control) to that string indicator, and to display it? I tried many ways, but since it is an output none of them worked. Is it possible to do that? Thank you.
I have also tried using a feedback node, but I think this somehow gives me an infinite loop.
In LabVIEW, an indicators state will be updated every time that it receives a new value.
By far the easiest way to do this is to simply run a data-flow wire into an indicator terminal.
Beyond that you have local variables, and property nodes which add additional concerns.
In your case it looks more to be an issue with the logic associated with your display update than with your actual updating of the value.
(Additionally, why are you using a string display to indicate a numeric value? Using a numeric suddenly simplifies all of your logic.)
To keep a running total - or similar value - in a loop, use a shift register.
This is just a minimal example in which the loop repeats every second until you click the stop button, but you can adapt it to how you want the control flow to work.

Can Access ensure a new form record displays all fields?

I have a database where I don't want some fields showing depending on data in other fields. I'm still new to VBA, having learnt how to do things I need via the internet (there's not much call for it in my job so like to try it out on side projects) for the things I need and have managed to create some code that hides certain fields that aren't needed, depending on what's been entered in another field and that works okay, if not perfectly (I'd like it to only work on the current record and not all of them at once but will worry about that later). My problem is, if I'm entering information onto a record and any of those fields become invisible exactly as I would want them to, then if I have more records to complete and load a new record, those hidden fields are also hidden on the blank record before any data has been entered and I want each new record to show all fields from the outset.
Another thing I've noticed is that if I close the database, next time I go into it the hidden fields have unhidden themselves again so I know I'm missing something important.
Here's a screenshot of a bit of the code where I want 2 other fields (What_reason and Date_sent_to_new_owning_School) to be visible depending on whether the answer in the current field after update is "Standard" or "Non-standard":
I'm sorry if this is really entry-level stuff but I AM entry level and trying to learn. This bit does work, albeit not perfectly as I'd like it to only work on the record I'm in at the time, and not go through and hide that field in all the other records at once (which it's doing).
I've searched everywhere but can't find the answer and although I've tried, I'm nowhere near good enough at VBA to try and use common sense to work it out. Is this something that can be done? I'm okay with computers generally and with Access too but I'm aware there's an awful lot I don't know and this is why I'm trying to do new things and learn stuff that I've not used before. I have tried all day to get this to work but am admitting defeat and am hoping somebody here will be able to help me. I'll probably need 'idiot level' advice if that's possible, I know my limitations. :)
Do you know how to use the Event tab in the Property Sheet? You can set all of your fields to [field].Visible = True on either: On Current, On Load, or On Open
Screenshot of the Property Sheet and for the field that determines the visibility of all of the other fields; you can use the Event: After Update so that way when you click/tab away from that field, it'll make those changes for you!
Property setting affects ALL instances of control. Control will be visible/not visible for all records depending on conditions of current record. Therefore, dynamically hiding controls on form set in Continuous or Datasheet will NOT give the desired result of
only work on the current record and not all of them at once
Db is not going to 'remember' dynamic setting - code needs to be executed when form opens and/or navigating records - so it is needed in OnCurrent event as well as control's AfterUpdate.
Conditional Formatting can dynamically enable/disable textbox/combobox by record although control is still visible.

How to know if a user has stopped their selection in a datagridview?

My scenario: I have a datagridview and it contains some data. User can select a row, or multiple rows in that datagridview, and they need to know a summary about those rows they selected.
Handling multiple rows in datagridview is easy enough, and I have no problem getting what the user need: Two numbers indicate how many item is selected, and their total weight in those rows. I passed that data to a small summary form to display, and I put the code to show that form under dgv.SelectionChange().
But then disaster follow: each time user select a row, that form will appear. Which is, if user select 20 rows, they will see 20 summary forms.... and any more than that, well.. you can imagine. I thought about putting something inside SelectionChange() to check if user has stopped their selection.. but can't think of any.
This seems like a very simple matter, but somehow I can't figure it out..
My question, how to know if a user has stopped their selection in a datagridview ?
I still don't have enough points to just comment, so my answer would be I don't think you can reliably without adding another control (ie, button). You can't read the users mind and since the number of rows can be variable, how would you ever know? You could try something like if the cursor leaves the DGV but that would be frought with issues as well. While it would be an extra click for those just selecting 1 row, I still think having a "Get Summary" button would be the way to go. Sort of like when selecting items to compare - you can click any number of items and while they may show which items you've picked so far in another area, the comparison table doesn't appear until you click the Compare button.
From what I understand, you actually have two options.
Add a button
Since you can't figure out when the selection is done, just add a button that will call the Form you want to display, that way you are sure that it will display only when user asks for it.
Use a timer
Another option is to use a Timer, every time the selection changed, you reset the timer to one second (to keep the example simple).
And whenever the timer does a tick, you call the Form and stop the timer. That way it will trigger one second (or less) after the user made the selection and gives him one second to change it...
Honnestly, I think the button option is the best, as you give the power to your user. Maybe they will want to select some rows but don't want to see your form, as they will only copy it to paste it somewhere else...

In Access VBA on a Form I want to use two listboxes to sort and reorder a set of field names

I'm trying to create a filter so the user can choose any of 40+ fields to display in a query result that has been dynamically created via VBA.
This is something I see standard in a lot of programs so I figure someone must have code that does it without me reinventing the wheel. Unfortunately I haven't been able to find it online.
Basically when it starts all the field names are listed in the left box and the right box is empty. The user can click a right arrow button to move the fields into the right box or a left arrow to remove them and put them back in the left box. Also the user can use up and down arrow buttons to change the order of a selected field in the right listbox.
Once I have the right listbox populated and ordered correctly I know how to execute the query properly.
If you are unable to find a full example for this then you'll need to work through it step-by-step yourself. Here is an MSDN link for the ListBox control. There are links to the various methods and properties of this control at the bottom of the page.
Essentially, clicking a button (your arrow(s)) triggers the Click event;
In this event you might need to loop through to find the Selected item;
If the listbox is multi-select then you can examine the ItemsSelected collection;
Then you would use the AddItem and RemoveItem methods to move them for right-to-left or left-to-right.
I cannot recall currently whether the Field List option is bound to the table, or whether it just populates the list once when the form is loaded. If it is bound then you would instead need to use the Value List option and use VBA to retrieve all the field-names, and use these to set the RowSource (you may be doing this already).
In either event (Field or Value List) I don't believe the lists can remain sorted automatically (unlike in VB.NET). You will probably need to split the RowSource up into a (dynamic) array, find a simple sort routine to sort the array, and reassign the sorted items as the RowSource.
An alternative would be to create two temporary tables and use ADO (or DAO) to insert and delete rows between them, then use SELECT statements each time to re-populate the lists. This has the advantage that the SELECT can include an ORDER BY clause to sort the lists each time. However, It perhaps involves a little bit more effort (to maintain, and delete, the temporary tables).
You might, however, want to continue your search as I suspect an example is out there somewhere. Good luck.

limit selections in a listbox in vb.net

I am creating a web control in vb.net that contains a list box. I know that I am able to choose a selection mode of Single or Multiple, but I am interested in limiting a Multiple selection to a predetermined size. For example preventing a user from selecting more than 3 items.
I have tried adding a Validator to the list box, which might be a way forward, but was wondering if there was a way of changing the selection mode to something a bit different than just the two specified ones.
Any ideas or suggestions would be greatly appreciated
Edit: Unfortunately due to project limitations I am unable to use Javascript on this problem. very annoying I know!
You could try handling one of the SelectedIndexChange events. With multiple selection, each time this event fires you can check how many items have already been selected. If it is more than you want, have the handler deselect the one that was just selected. You could also put up a little red label under the listbox saying "Sorry, no more than [n] selections allowed."
EDIT:
Just noticed you said WEB. Same theory applies, but it would have to be done using Javascript.
On the SelectedIndexChanged event, write a short piece of code that will check the number of selected items and if it is greater than your desired amount, unselect the new selection (or unselect the oldest one, or however you wish this to operate).