How can I clear a specific filter without clearing all filters? - google-apps-script

Background:
I am creating an app that stores record of trainings that employees in a company took in table. I want to filter the rows of the table based on training name and/or employee name. I was able to figure out this first part, and I was able to create a button that clears all the filters and reloads the entire table using the clearFilters() function.
Problem:
I want to create two buttons that clear the filter selections one ("All Trainings") for the training name and one ("All Employees") for the employee name. To be more clear, when I click on the "All Trainings" button, I want to clear the filters on the training name, but not on the Employee name. This will become useful once I have a table with multiple fields that I want to filter, and I want to navigate the table without having to reset all fields every time.
I tried searching the functions available on Google App Maker, but there was nothing that seemed to be able to solve my problem. Any suggestions?

From the Reference about datasources:
https://developers.google.com/appmaker/models/datasources#query_datasources
Like field filters, assigning null to a relation filter property clears that restriction.
So, something like:
datasource.query.filters.Employee._contains = null;
datasource.load();
should work for you.

I am sure there is a better way to do this, so you may want to wait for someone smarter to chime in, but I BELIEVE you can just have your button clear the filters, but reapply a new filter.
So for my situation I have the table do a filter for items that are listed as "Complete", so those are hidden when the user opens the page.
Then, when the users filter another field and want to clear out that search I didn't want the "Complete" items to reappear (which is what happened when I just used the clearFilters() function. So my workaround was to make the clear button actually clear the filter, but apply the original "Complete" filter.
So for my OnClick action, for my "Clear Button" I have:
widget.datasource.query.clearFilters();
widget.datasource.load();
app.closeDialog();
var datasource = app.datasources.TestModel;
datasource.query.filters.Status._notContains = 'Complete';
datasource.load();
The
widget.datasource.load();
app.closeDialog();
May be redundant/unnecessary.

Can you simply take 3 steps in your onClick handler?
(1) clear all filter
(2) set the employee name filter
(3) load data

Related

How to populate data in a one to many relationship between two forms when the target form's table has no matching entry?

This is probably a dumb question, but I'm a noob, so forgive me. I have two tables with a one to many relationship based on a OrderNumber. Essentially, I have some order details in one table, including OrderNumber (the one side of the relationship) and I am trying to get a list of LotNumbers in the other table using the OrderNumberLot (the many side) to link them together, as there can be many lot numbers on one order. The primary key in tblOrderDetails is OrderNumber and the primary key in tblLotNumber is LotID (auto number), but the linked field is OrderNumberLot. I made a open form button located on frmOrderDetail to open frmLotNumbers (based on the tblLotNumber). The deal is when frmLotNumber opens the OrderNumberLot field is blank. I understand there is no associated record in tblLotNumber, because I am trying to enter it, but how do I get the OrderNumber from the previous form, frmOrderDetail, with the button to automatically populate in the OrderNumberLot field in frmLotNumbers? I certainly don't want people to have to type it, because they will screw it up as badly as I have this explanation of my question! Thanks in advance for the help.
I agree with June7 on using a subform-approach for your purpose.
If you already have created the form, you could simply drag it from the sidebar onto your mainform and set the "Link Master Fields" and "Link Child Fields" to "OrderNumber" and "OrderNumberLot" - or you just use the subform-wizard and follow its instructions.
Though, some people dislike subforms in general and try to avoid them whenever possible - which might make sense at further stages of development. Instead of subforms, you could then use vba to transfer information from one form to another.
Lets say your button is named bt_openform
Private Sub bt_openform_Click()
'Open the desired form. The option "acFormAdd" forces the form
'to add a new entry whenever loading and requerying.
'As we want to add a new record, we will not use the filter settings
DoCmd.OpenForm "frmLotNumber", , , ,acFormAdd
'Next, store information from the initial form into the newly opened form
'To refer to data from the current form (meaning the one, in which the Sub is triggerd),
'you can use "Me.fieldname" and to refer to another form, use "Forms!formname!fieldname"
Forms!frmLotNumber!OrderNumberLot = Me.OrderNumber
End Sub
You could also do it the other way around and retrieve the information when loading the form:
Private Sub Form_Load()
Me.OrderNumberLot = Forms!frmOrderDetail!OrderNumber
End Sub
To be on the safe site, one might want to nest this function in an if statement, to check whether frmOrderDetail is open or not. This way, you can open your frmLotNumber from different forms without causing troubles
If CurrentProject.AllForms("frmOrderDetail").IsLoaded Then Me.OrderNumberLot = Forms!frmOrderDetail

Method 'Parent' of object failed

I have MS Access 2013 and I'm trying to make a search form that populates other details when a row inside a subform is selected. I figured out how to get which row is selected, and which column, but now I need to pass that information to the parent form so I can populate the other things on the form.
So on my form's subform, I made an On Click event:
Option Compare Database
Private Sub Form_Click()
MsgBox(Me.Name) ' returns P_pat subform
MsgBox(Me.Parent.Name) ' says 'Parent' failed
But it can never find its parent. I also tried on a few other events but the results were the same. The Access form looks like this:
The highlighted subform is the one I'm trying to work with, and I want it to call the parent so that the parent can populate its other child subform (the one below the highlighted form).
I feel like I slammed into a brick wall that shouldn't be there and my pride hurts.
How do I get the parent?
I know that I can simply set the record ID I selected with a global variable, but I have no way of triggering an update event for the other subform.
Any help or advice?
There doesn't look like there is anything at all wrong with your code. So from research there seem to be three possible solutions that I have found so far:
Make sure there are no special characters in your forms' names
Compact and repair
Create a new blank project and import all of your database into the blank project

MS Access 2010- How to update field on one table based on field in another table

I'm designing a database to track requests. Currently, I have a form that its' record source is based off a query "Unassigned Requests". This query is based off my table Requests, and returns all "unassigned Requests". In this form, I would like the status field to change to "Assigned", once a Tech field has been assigned to the request. I currently have the Default for the Tech Assigned field set to "Blank', and the status field set to 'Unassigned". Both of these fields are combo boxes. The status field has a control source from the request table and row source from the status table. The tech assigned field has a control source from the Tech table and the row source is based off a query.
I have tried multiple solutions that have not seemed to work. I have limited experience with Macros and VBA. I would appreciate any suggestions on solving this problem.
I am going to make some assumptions regarding your post and if any are incorrect please let me know.
You have a request form where a request is assigned to a Tech. On that form there is a dropdown for the status, and also for the Tech.
You want to make it so when the tech dropdown is filled out with a tech's name you want the dropdown to change to assigned.
If this is the case I would recommend using the Tech Assigned field's AfterUpdate event. The code would look something like this:
Private Sub cboTech_Assigned_AfterUpdate()
If Nz(Me.cboTech_Assigned.Value, "") <> "" Then
Me.cboStatus = "Assigned"
Else
Me.cboStatus = ""
End If
End Sub
Obviously you will need to adjust to your own naming scheme. I should also point out that I don't even know if that Nz function is needed, I have just gotten into the habit of putting it everywhere. If I misunderstood something about what you want to do please let me know!

How to implement an auto refresh on a datagridview bound to a MySQL database in Visual Basic (.NET)

I have a visual basic program with a datagridview that is bound to a mysql database upon loading... I also have fields where you can update selected rows, add, delete, etc. and I'd like to have an auto-refresh upon updating... However, I cannot figure out how to do this as the table just adds the new rows underneath the old rows. Is there a way to have a complete table refresh for the mysql bound datagridview without having to re-launch the program?
Thanks in advance!
The grid is not bound to MySQL. It's bound to a DataTable. If you want a complete refresh of the data then simply clear that table and then repopulate it.
myDataTable.Rows.Clear()
As jmcilhinney suggested, datagridviews are bound to DataTables (or sometimes lists in my own case), so what he said sounds like it should work. Since, apparently, it didn't do as you wanted, here's my suggestion:
You said you have "fields" where you can update, add, delete, etc. a selected row, correct? It also sounds like you're doing something with new rows. As you've suggested that it's a databound gridview, I doubt that you're actually adding them in the typical way but instead have some sort of programmatic alternative.
So, try implementing your solution as less of a "rewrite" and more of a SQL update. When the user enters the data for the row that they wish to update or the new row they'd wish to create, search the rows for a given primary key.
In the case of a datatable, the code would look something like this:
string s = "primaryKeyValue";
DataRow foundRow = dataSet1.Tables["AnyTable"].Rows.Find(s);
foundRow.Item["DesiredColumn"] = newValue;
source: https://msdn.microsoft.com/en-us/library/y06xa2h1.aspx
In the case of a list bound as a DataSource, I believe you'd have to do something like this:
List<Thing> things = new List<Thing>(); // in case this wasn't obvious
Thing tempThing;
tempThing = things.Find(x => x.PartName.Contains("seat")));
tempThing.Value = newValue;
After you've modified the underlying datasource, then, theoretically, you should be able to simply call DataGridView.Refresh(), but you may have to do something trickier like set the datasource to null and then rebind it in order to force EndEdit.
I know this is late, but I hope it still helps someone.

In VBA/Access get value from current record when changing records

I have an Access database. I have a map control embedded in a form (using MapInfo, but that's not important). When a user goes from one record to another I would like the map to re-centre on the appropriate coordinates. To do this I need to get the coordinates which are stored in the current row of the table which is the data source for the form. My question is how I access this value. This is pretty simple, right?
I have worked out that the "On Current" event is triggered when the record is changed but I can't seem to refer to the xcoord and ycoord fields in the current row.
This page seems to suggest that I need to create a module to do this. Surely there's a simpler way?
Thanks in advance!
Update: If I put a pair of textbox controls in the form that display the x and y coordinates then I can access them by doing Me.x_coord. Is this the answer?
In Access VBA you can reference the fields of a bound form's recordsource with the syntax:
Forms!your_form_name!your_field_name
In your case, you can grab the current x_coord with Me!x_coord. No need to bind it to a control to get the data.