MS Access keep ID field in subform filled with ID from parent form - database

Everytime I jump to where I can enter e new record, the ID field from the parent is empty and so the connection is lost. I am looking for a workaround.
My Setup
I have a parent form that deals with two 1:n relationships
(school-class --> pupils, school-class --> tests).
For the first relationship I used the wizard. Everything works find. For the second I show the connected tests in an unbound list. Under the list is a button opening the form for entering a new record (test) for the class I came from (parent form). So I filter the sub-form via VBA so that only the tests of the current class are shown. That works perfectly fine, too.
When moving through the tests already connected with the class the correct ID (of the class filtered) is the value of the corresponding input field. But when I come to the new new record state (all fields empty), then the connection to the parent breaks and the user has to manually enter the ID of the parent (school-class).
My Question
Is my setup correct?
Is there a better way to create a subform that offers to (only) enter a new record connected to the parent data? (Maybe without the ID input field in the subform and passing of forcing the value via VBA?)
Thank you for your time!

You can use Default Value to set the classid of Tests form but be sure the parent form is open in background or behind the pop up.
Under Property Sheet/Data tab of Tests form's classid control, enter in Default Value cell:
=Forms!parentformname!classid
Alternatively, in VBA in the Tests form's OnOpen Event:
Me.classid.DefaultValue = Forms!parentformname!classid
You can then choose to hide (Visible - No) this classid control so users do not modify it. It's always advised to never allow users control of primary and foreign keys.

Related

MS Access Foreign Key Record Fill Too Fast

I have a problem with one of my forms in my MS Access database, and strangely it's the only form that has this problem.
The form has a typical Master/Detail structure, with the subform tied to a table. The subform record source includes a foreign key that pulls information from another table and populates the rest of the fields based on the key value. This foreign key is a Material number that defines a specific object in an inventory, and the other fields in the subform show details of this object.
Example from Signs table:
Material number: 116063175
StorageBin: A116
Material Description: Stop Sign
Dimensions: 48x48
All of this information is contained in the same table, but the form is for a table that is used to fill in what signs are on a particular road (stops, speed limits, etc.)
On all my other forms, when I type in the material number and shift focus anywhere else, the rest of the forms will fill in automatically. This process works here too, but for some reason Access wants to try to fill in the rest of the field data before I have finished typing the material number. I'll type "1" and access will throw an error that it cannot find a matching record in the Signs table in the foreign key's table. After rejecting the error twice, the data entry can resume as normal, which is also strange.
I hope I've been clear enough, this is my first time asking a question here.
Thanks in advance!
Edit: Tried re-building the form, same issue. Built another form similar but without my multiple comboboxes, didn't have the issue! Could this be due to underlying requery code in the Afterupdate event of my comboboxes? I have a cascading combobox setup on the form, could data entry be triggering a requery?
Edit2: for the time being, a fix that I am using is to make the material number and quantity (the two important fields for this form) into text boxes outside the subform, that the user can edit then place in the subform with a button click, which is coded as so:
Private Sub Command1_Click()
If Me!PrimaryRoadInventorySubform.Form.Dirty Then
Me!PrimaryRoadInventorySubform.Form.Dirty = False
End If
Me!PrimaryRoadInventorySubform.SetFocus
DoCmd.GoToRecord , , acNewRec
Me!PrimaryRoadInventorySubform.Form!MaterialNumber = MaterialNumtxt
Me!PrimaryRoadInventorySubform.Form!Quantity = Quantitytxt
End Sub

ExtJS synchronize record between clients

I'm trying to do something fun: I'd like to send the record changes from one client to another and have the second client updated to show these changes. Basically collaborative viewing. The second client is disabled from making changes, he can only watch.
Simple fields like strings, numbers, checkboxes, etc. are easy, that worked right away.
The references are the problem. If I have a combo that uses another model as it's source, I am unable to update it on the second client.
I tried setting just the id, then the entire referenced object, I tried various set options, but simply no dice.
The record does change, I see that the data is updated, I was even able to manually modify the _ reference attributes, but the UI keeps showing the old values for those fields.
Is there a way to send the record from one client to another and have the other client just take over all values and display them in the UI? (it would be better to send just the changes, but I'd be very happy if I could get it to work with the entire record)
EDIT: I'm using SailsJS with socket.io, so the p2p connection is not the issue.
I'm getting the data like this:
var data = record.getData(true);
broadcastRecord(data);
And on the other side I tried:
record.set(data);
A code example for the receiving side would be appreciated, if anyone has an ide how to solve this...
I think your problem is related to associations and comboboxes.
Let's say you have a model User with a field group that references model Group, and that you have a User form with a Group combobox.
In the receiver client, you are probably getting only the group id. record.set(data) updates the bound combobox calling setValue(groupId).
This setValue will try to find the corresponding record inside its store, but it won't ask server-side for that record. Instead, it will create a new record with the passed id (showing an empty combobox).
If possibile, you can set remoteFilter:false to the store and queryMode:'local' on the combobox and preload all the data from that store.
Otherwise, I think you'll have to override the combobox setValue method to get the record remotely.

How can I get the ID of a record when it isn't mentioned on a form in Access 2007 via VBA?

I have a multiple items form which does not mention the ID of the record. I have a button for each row which, when clicked, opens up a new form containing more details.
In the past, I've added a field for the ID but made it invisible, but this seems silly - the ID is a unique field of the original query, so I should be able to access purely with code somehow.
Does anybody know how to do this? Let me know if you want more clarification.
Update
The fastest way for me to do this is to add a field in the form for the field in the query, call it the query field name, save it all and close it, then delete the field. Though of course I'd rather just be able to do Me.ID without any of that prior nonsense.
In some cases, you may have to refer to Me!ID, rather than Me.ID because the field has not been added as a property of the form (discussion: http://tek-tips.com/viewthread.cfm?qid=1127364 )
When you add the ID as as control and then delete it, it becomes a property of the form, which is why your work-around works.
If a form's record source includes a field named "ID", you can access the field's value as a property of the form:
Debug.Print Me.ID
That works without a control bound to the field.
you probably need to edit the recordsource / query.. and add that column as an available field.

Populating a field in wpf

I have a database of finance info and i want to check that supplied totals 'add up'. I have added fields to the database for the check data and am using data binding via the Entity Framework. How do i populate these 'check' fields while the user is adding data to the record?
Eg The form contains SubtotalA, SubtotalB and TotalAB textboxes. The database has these fields plus CheckTotalAB. The user keys in SubtotalA, SubtotalB and TotalAB from a hard copy form. I want to populate CheckTotalAB with the sum of SubtotalA and SubtotalB to compare against the provided TotalAB.
I first tried getting the data from the textboxes. Unfortunately txtSubtotalA.Value doesn't exist.
I then thought I'd have to go to the entity itself. Unfortunately I don't know how to access the current record/entity being entered and if I did, how would I access the value of fields that haven't been saved yet.
Can someone point me in the right direction?
tia
mcalex
Accessing the entity was the answer. This was accomplished through use of an entity property in the datacontext that i set to equal a class member i added to my form class.
After that getting to the entity's fields including my calculated fields was just a case of getting/setting the member's properties.

Fill in Form Field from Node-Field using Rules in Drupal 7

I am looking for a way to populate some fields in an (entity)form (for example name and email) once a client has filled in his tax-number (or another configurable field). The field to compare it to is in another node or entity.
For example:
A registration form for an event => when a user is registrating: check
if the filled in tax number allready exists in one of the nodes
'attendees last year'. If it finds a match, it takes the date in the
'name' field of the node, and puts it in the 'name' field in the form
(in the next step, see underneath)
For the forms I am using the EntityForms-module (which creates a form with the fields of an entity, so users can create new entity objects) and a custom module which allows me to go through the form in multiple steps, a rules event is triggered when the 'continue' button in a form-step is clicked.
I have rules and rules-forms-support enabled, I try to make a rule:
Event: my custom continue button is clicked
Condition: entered date from a (to be selected) field from the
form allready exists in a (to be selected) node's field
action: the (to be selected) field from the node is put in the (to
be selected) field on the form
I can't hardcode this because it has to be configurable (have to make multiple different forms..)
You may be able to do this via a value in the URL. Checkout Prepopulate module http://drupal.org/project/prepopulate
There is a dev version for Drupal 7.
You should be to add the extra info in the URL in the Rule.

Resources