Unbound Subform with Multiple Link Filters? - sql

I have a sub form tied to a table. This table has a foreign key, which holds the key to different tables, depending on the value. Based on the value, the information in the record is tied to a certain object level in the schema. It may be tied to the main record based on the main entry form. It may be tied to another subform record, etc.
So let's say the main form is for projects. For each project they could be placed into many buildings. Within each building they may have multiple staff. This somewhat inter-dependent sub form is for project documents. They may relate to the current project. They can also relate to one of the buildings for the current project, but only for that current project. Or the document could relate to one of the buildings, but for all projects. I already have a combo that gets it's row source based on the relationship type/doc type combo that is chosen first. That let's the user choose the actual building, staff or whatever the doc is related to.
I need to create a filter for the sub form that will give all records related to that main record and/or it's sub records, and still be able to add new records. I've been looking at a case statement, but concerned that will only apply the first true case. I was thinking of a union, but guessing I won't be able to add records. It won't be updateable.
Any suggestions appreciated!

Thanks. I ended up creating 2 sub forms. One for viewing all records that are somehow tied to the main record. This has a record source set to a union view, with a where clause for the main record ID. The second form is for adding/editing new records and the record source is tied to the documents table, with a filter to the record being edited, or the data entry set to yes, for adding new records. This is all set based on a toggle button, new main record activity, etc.

Related

How do I reset numbering on an Access subform when a new master record is added?

Having not looked at an Access db for about a decade, I find myself in need of a simple VBA (or best method) solution.
I have created a master form with two subforms.
The master form (frmProjectData) contains an autonumber ID field. It houses the primary key.
The subforms (frmFeatData and frmFutuireFeatData) are linked to the primary key via dummy (non-visible) number fields. Each subform also contains an autonumber field (not linked) that numbers each subrecord as it is entered.
The forms seem to work well together, with both subforms capturing as many records as needed and tying them to their appropriate master record. I would like to have the subforms restart numbering at 1 each time a new blank master record is opened. I recall bits and pieces of code, but nothing I've tried seems to be working so far. Any help is appreciated.

How to entry more than one value for a feature in sql

I have a project that is a clinical web based system, I need to save some sheet data in SQL database.
I have "TumorSite" table, by this table I show checkboxes that user can select one or more of them in MVC 5.
I also have "PathologyReport" table, I wanna to save all of the data about pathological data of a patient into it.
Some fields in "PathologyReport" should be complete from checkboxes that checked, some not and fill from textboxes. For checkboxes, if the user checks "other" another value should b saved.
How to fill multiple checkbox values for a patient? Do I need another table?
How to link "PathologyReport" to the new table?
What should I write in the controller in mvc?
please see my form.
Yes, you usually need another table for that. Some SQL databases allow an "array" data type for columns (e.g. Oracle), but the usual approach is another table with a foreign key.

Counting value list items in FileMaker

Please see link to FileMaker Pro 12 database I've created to illustrate my problem:
https://dl.dropboxusercontent.com/u/24821795/Example.fmp12
I want to count the number of times an Activity has been assigned to a Staff member, but there are a couple of things making it tricky (not impossible, I hope):
When the user performs a Find, the count should update to only include the found records.
The user can add to the list of activities.
In the example provided, SelfJoinCount and Activities::Count are not what I want - they both count Activity (e.g. Archery has been assigned to two staff members), but do not meet criteria 1. above.
Try performing a Find of Gender = M
The values of ReviewedCount (a summary field, counting Reviewed) change to 3, which is what I want.
The values of SelfJoinCount and Activities::Count do not change. In this case, I want them to change to 1 (i.e. One record with Ballooning, one record with Bird watching and one record with Archery in the found set).
I could create a calculation field with a 1 in it if the activity occurs and then a summary field counting that 1 for every single activity in the database, BUT this won't work because of criteria 2. above (also, there are a lot of activities).
Any ideas?
Ok, several problems you have here.
First, you need key values for your tables. This can easily be accomplished by creating a number field in each table. In the options, select auto-enter serial number, validation unique, not empty.
Now, you need a 3rd table for the join. This table will have the foreign key value for the Staff member as well as the foreign key for the activity.
You will want to have your Staff layout in form view, add a portal into the join table with they foreign key field for the activity. Create a popup or drop down list for activities (hint: if you want the name of the activity to show in the layout rather than its key, use a popup.) it needs to have they key value and display second field, all values, show only value from second field.
This will allow you to have a many to many relationship between the tables so that a single staff member can have many activities and an activity can have many staff members.
Now, if you want a count of each activity, you could of course create calculation fields in the staff table to count instances of each activity type, but I find that cumbersome and time consuming as well as requiring you to create TO's for each activity. What you really want to use is an ExecuteSQL() function. Some thing like this:
ExecuteSQL("
SELECT COUNT(J.FK_ActivityID)
FROM JoinTable J
WHERE J.FK_StaffID =?
Group by J.FK_ActivityID";"";"";Staff::PK_StaffID)
You can tweak that ExecuteSQL to include a specific activity, or leave it as it is an include them all. Up to you how you do it.
If it wasn't 7am and having had no sleep, I would mock up the file for you, but I think you would do better testing it and working on it on your own.

You cannot add or change a record because a related record is required vb.net

I know this question has been asked numerous times, but the situations people had were slightly different each time, or lacked enough detail, or the explanation for the problem lacked specific detail that I could understand the solution.
So here is my thing. I've got a combobox called "StatesComboBox" in a form that takes in customer data. This form is bound to a table called "States" in an ms access database file. So whatever states are in that table are reflected in the StatesComboBox.
In my access database file, I've got a table that stores the customer data called "CustomerData". One of the fields in it is called "customerstate", which stores the "StatesComboBox" selection made by the user.
I have connected the "States" table to the "CustomerData" table with a relationship. It connects the States table to the "customerstate" field. This is a one-to-many relationship, and I have checked off on the enforce referential integrity, cascade add and cascade delete options.
Now, when I enter data in the form and hit my register button, I get the message stated above - "You cannot add or change a record because a related record is required in table 'States'". But when I go back to access, delete the relationship between "States" and "CustomerData", the data gets stored just fine.
But I need to enforce limitations on the states selected... What am I doing wrong? What can I do to address this? Thank you.

Access 2003 - Create and Delete Many-To-Many associations

I need to develop a front end to a MSSQL database just to modify a few tables. I decided to use Access 2003 simply because of time restraints.
I used Linked Tables over ODBC to get them into Access, I'm designing the forms but I'm having problems creating an interface to allow users to create and delete new association between entities.
My Database structure is:
product
# productcode
- name
product_part
* productcode
* partnumber
- position
part
# partnumber
- comment
There is a many-to-many relationship between product and part (a product can have many parts and a part can belong to many products) except I can't find any easy way to allow a user to just associate a new part to product, only view the existing ones.
I've defined the relationships in Access except the options for cardinality and referential integrity are greyed out, I'm assuming this is because they're linked tables? Not sure if this would affect anything.
I created a form for product with an embedded subform which lists all the associated parts and their position (position is an attribute of the relationship since it's contextual but I can spin this out into it's own table if it'll make things easier).
Basically I need to make an user interface mechanism which will associate a selected part from a list to the shown product or any other way to create new and delete existing associations flexibly. I would have thought Access would have something in some wizard somewhere to do this, but if it does I can't find it.
Any help would be appreciated.
Judging on what noted so far, then this should be a simple matter to have the main form based on your topmost table (product). The continues sub form should then be based on ONLY the product part table.
If you think about this, the third table is really only a lookup table there for your convenience to allow you to not have to type in manually type in the part number.
So, base the child sub form as a continuous form, and make that column for part number a combo box that looks up the part numbers from the third table (part). So this combo boss can search and display by description, but will in fact automatically store the part number in that colum for you.
So while there's no need for any types of wizards, you certainly do not have to write any type of code whatsoever. Just ensure that the master child link settings for the sub form are set up correctly, and access will thus insert and maintain The product code columns used to link back to the main product table. You can most certainly use the combo box wizard to create the combo box in the continuous sub form that you're going to use to Select what part and set the part number column from the parts table.
The result will be a form that allows you to add new part assemblies or edit existing. While access will maintain the product code column for you, if you delete a main record, you'll need to have setup referential integrity and cascade deletes on the back end database part. So as you correctly note, all the integrity features will be set up in the database back end, not in the access front end part.
I've discovered what I wanted to do isn't easily possible using Linked Tables, I was able to do what I wanted to do easily if I used native access tables (since it let me properly define the relationships) but I couldn't do that with linked tables.