Hide elements in list view for non active records in Filemaker - filemaker

I've got a list view of a number of records. I would want to hide certain layout elements on the records which isn't the active one. Is this possible?
It should be possible with the "Hide object when"-functionality, but I'm not sure what the calculation should be.
I'm using Filemaker 13.

You can use a Script Trigger to set a global variable (e.g., $$ID) with that record's Primary Key (ID) when a record is loaded, then hide the button/layout object if not $$ID = PKID.
Adapted from the technique at http://forums.filemaker.com/posts/e591b47fdc.

Just create a statistic field in your table that counts the current number of any field that is filled in every record. An ID or timestamp would be the best guess. Then hide your portal object(s) in the inspector with "YourFieldName" <> Get(ActiveRecordNumber). Should be done.

Related

Code to assign an ID when button is clicked

I have designed a simple database to keep track of company contacts. Now, I am building a form to allow employees to add contacts to the database.
On the form itself, I have all the columns except the primary key (contactID) tied to a text box. I would like the contactID value to be (the total number of entered contacts + 1) when the Add button is clicked. Basically, the first contact entered will have a contactID of 1 (0 + 1 = 1). Maybe the COUNT command factors in?
So, I am looking for assistance with what code I should place in the .Click event. Perhaps it would help to know how similar FoxPro is to SQL.
Thanks
The method you recommend for assigning ContactIDs is not a good idea. If two people are using the application at the same time, they could each create a record with the same ContactID.
My recommendation is that you use VFP's AutoIncrementing Integer capability. That is, set the relevant column to be Integer (AutoInc) in the Table Designer. Then, each new row gets the next available value, but you don't have to do any work to make it happen.
There are various ways to do this. Probably the simplest is to attempt to lock the table with flock() when saving, and if successful do:
calc max id_field to lnMax
Then when inserting your new record use lnMax+1 as the id_field value. Don't forget to
unlock all
... after saving. You'll want to ensure that 'id_field' has an index tag on it, and that you handle the case where someone else might have the table locked.
You can also do it more 'automagically' with a stored procedure.

Filemaker - Can I use a portal like a drop-down value list?

I am trying to work around a limitation that Filemaker 12 seems to have. In a value list that links to an ODBC attached SQL Server database, it doesn't display every piece of data. If there are 2 people with the same last name for example, it only displays the first person with that last name in the list. This is verified by the following in the Filemaker documentation (which I found after a lot of digging)
If the value list is defined to display information from two fields, items will not be duplicated for the field on which the value list is sorted. For example, if the value list displays information from the Company field and the Name field, and if the values are sorted by the Company field, only one person from each company will appear in the value list.
Portals on the other hand will find all the related data, I just don't understand how do something with the data once I get it in the portal. I essentially thus wish to use a portal AS my drop-down value list, and then to use it as I would have a value list (which is then to act as the key to do the rest of the lookups on the page to fill out the invoice.
The major issue here (other than this maddening choice Filemaker seems to make) is that the external file I am pulling the data from is an ODBC mounted SQL Server file, so I can't do something easy like a calculated field which would give me last name & " " & first which would make almost every person unique. Filemaker won't let me do that because it says I can't do that with a field that is not indexed. Any help would be greatly appreciated!
Assuming that we're starting with table MyTable and we're trying to get a ID from the People table for the selected person, which we'll call ID so that we can put it into MyTable::PersonID
Start by creating a new Table Occurrence of your People table and call it PeopleWhoCanBeSelected. If you want every person in the People table you can connect it to MyTable with the X relationship. If you want to show just a subset of the people you can build a different relationship.
Now, on a layout displaying records from MyTable you will make a portal showing records from the PeopleWhoCanBeSelected table.
In the portal put a button. When that button is pressed use the Set Field script step:
Set Field MyTable::PersonID to:
PeopleWhoCanBeSelected::ID
That should do it. You can make the button an invisible overlay on the entire portal record if you like, so that the user clicks on "the name" instead of "the button next to the name".
Now, if you want to pull additional data through to the MyTable record, you'll need to create a second Table Occurrence, called People with the relationship MyTable::PersonID = People::ID. Then you can get information on the specifically chosen person through that relationship.

Access comboxbox selection needs to change value in label control

On a form, I have a combobox, with the RowSource coming from a query (specifically, a calculated field in the query). When the user makes a selection, I want to update a label on the same form with a different column from that same query, but of course associated to the selection.
I'm fine with VBA and writing queries and whatnot, but I am not very familiar with Access forms.
By the way, I tried searching for an answer to this, but it was quite difficult because I don't know what this thing is really called that I am trying to do. A good link to a site explaining this would be perfectly fine (no need to write a bunch of stuff here if it already exists elsewhere).
In the After Update event of my combo box, cboUserID, I can set a label control, lblFoo, to the value of the second column in the selected row of the combo.
Me.lblFoo.Caption = Me.cboUserID.Column(1)
If your combo box is bound to a field in the form's record source, you may want to do that same operation from the form's On Current event also.
You can use the column property to refer to anything other than the bound column of a combo.
Rowsource: SELECT ID, SName, FName FROM Table
Me.MyCombo.Column(2)
This would return FName.
-- http://msdn.microsoft.com/en-us/library/aa224084(v=office.11).aspx
Me.MyLabel.Caption = Me.MyCombo.Column(2)

renumbering a ID field

Very new to Filemaker. Using Filemaker 11 pro.
I was wondering if it was possible to renumber an ID field column after doing an insert new record in between records? Maybe using a script trigger?
thanks
I agree with Jesse that renumbering a record's unique ID/Index doesn't sound like a good idea and more information or an example of what you're trying to do would help.
If you simply want to display the Record Number, you could create an unstored calculation field with the calculation "Get ( RecordNumber )". This should always display which record, of the found set, is being displayed. FileMaker's definition is available here: http://www.filemaker.com/help/html/func_ref2.32.55.html
If, on the other hand, you're trying to make a unique sort order for the records being shown, it is best to do this by creating a new SortIndex numeric field. (You'd need to make certain that the layout that you're displaying was always sorted by the SortIndex field which can be done using layout script triggers and, possibly, overriding the Sort menu commands using Custom Menus.)
One method to consider would be overriding the New Record command using Custom Menus. When New Record is selected you might route it to a script which does something like this:
Get the current SortIndex value
Get the value of the SortIndex for the next record (by creating a self-join which shows records where the SortIndex > the SortIndex of the table occurrence your view is based on)
Place the average of those two values in a $variable
Create a new record and set its SortIndex to $variable

Create a new FileMaker layout showing unique records based on one field and a count for each

I have a table like this:
Application,Program,UsedObject
It can have data like this:
A,P1,ZZ
A,P1,BB
A,P2,CC
B,F1,KK
I'd like to create a layout to show:
Application,# of Programs
A,2
B,1
The point is to count the distinct programs.
For the life of me I can't make this work in FileMaker. I've created a summary field to count programs resetting after each group, but because it doesn't eliminate the duplicate programs I get:
A,3
B,1
Any help much appreciated.
Create a a summary field as:
cntApplicaiton = Count of Application
Do this by going into define fields, create a field called cntApplication, type summary. In the options dialogue make the summary field a count on application
Now create a new layout with a subsummary part and nobody. The subsummary should be sorted on Application. Put the Application and cntApplication fields in subsummary. If you enter browse mode and sort by Application you ought to get the data you want.
You can also create a calc field with the formula
GetSummary(cntApplication; Application)
This will allow you to use the total number of Applications with in a record
Since I also generate the data in this form, the solution I've adopted is to fill two tables in FileMaker. One provides the summary view, the other the detailed view.
I think that your problem is down to dupliate records and an inadequate key.
Create a text field called "App_Prog". In the options box set it to an auto-enter calc, unchecking the 'Do not replace...' option, and use the following calc:
Application & "_" & Program
Now create a self join to the table using App_Prog as the field on both sides, and call this 'MatchingApps'.
Now, create (if you don't alread have one) a unique serial number field, 'Counter' say, and make sure that you enter a value in each record. (Find all, click in the field, and use serial number option in'Replace Field Contents...')
Now add a new calc field - Is_Duplicate with the following calc...
If (Counter = MatchingApps::Counter; "Master Record" ; "Duplicate")
Finally, find all, click in the 'Application field, and use 'Replace Field Contents...' with a calculation to force the auto-enter calc for 'App_Prog' to come up with a value.
Where does this get you? You should now have a set of records that are marker either "Master Record" or "Duplicate". Do a find on "Master Record", and then you can perform your summary (by Application) to do a count of distinct application-program pairs.
If you have access to custom functions (you need FileMaker Pro Advanced), I'd do it like this:
Add the RemoveDuplicates function as found here (this is a recursive function that takes a list of strings and returns a list of unique values).
In the relationships graph, add another occurrence of your table and add an Application = Application relationship.
Create a calculated field in the table with the calculation looking something like this:
ValueCount(RemoveDuplicates(List(TABLE2::Program)))
You'll find that each record will contain the number of distinct programs for the given application. Showing a summary for each application should be relatively trivial from here.
I think the best way to do this is to create a separate applications table. So as you've given the data, it would have two records, one for A and one for B.
So, with the addition of an Applications table and your existing table, which I'll call Objects, create a relationship from Applications to Objects (with a table occurrence called ObjectsParent) based on the ApplicationName as the match field. Create a self join relationship between Objects and itself with both Application and Program as the match fields. I'll call one of the "table occurrences" ObjectsParent and the other ObjectsChildren. Make sure that there's a primary key field in Objects that is set to auto-enter a serial number or some other method to ensure uniqueness. I'll call this ID.
So your relationship graph has three table occurrences:
Applications::Applicaiton = ObjectsParent::Application
ObjectsParent::Application = ObjectsChildren::Application, ObjectsParent::Program = ObjectsChildren::Program
Now create a calculation field in Objects, and calculating from the context of ObjectsParent, give it the following formula:
AppCount = Count( ObjectsChildren::ID )
Create a calculation field in Applications and calculating from the context of the table occurrence you used to relate it to ObjectsParent with the following formula:
AppCount = ObjectsParent::AppCount
The count field in Objects will have the same value for every object with the same application, so it doesn't matter which one you get this data from.
If you now view the data in Applications in list view, you can place the Applications::Application and Applications::AppCount fields on the layout and you should get what you've requested.