Autofill value in subform based on value in parent form - ms-access

I am creating a subform (in datasheet view) based on a query (qryClientEmployment) to display employment history for the client whose information is stored in the parent form (frmClientInformation). frmClientInformation is based on another query (qryClientInformation).
I have a filter on qryClientEmployment to select records based on the client ID field displayed on the parent form (frmClientInformation).
I WANT to be able to add new employment records to the subform and have access autofill the client ID based on the ClientID field on the parent form.
I have tried, without luck, setting the default value on the Client ID field on the table (which stores Client Employment history) equal to form!frmClientInformation!txtID.
I’m new to Access and am stumped.

When you are new to Access, it is nearly always best to use the wizard to create controls. In this case, it would have offered you the option of adding Link Child Fields and Link Master Fields, and these are what you need. You can edit these properties for the subform control, but you must be careful to select the control, not the form contained. Link child fields will be completed with data from the parent form master field, a misleading name, because the link master field can be a control. You can have multiple link child and master fields separated by semi-colons.
Do yourself a favour and change from datasheet to continuous form, you will have much more control.

Related

Checkbox per row in multi user access database

I have the following situation:
I have a many to many relationship.
For example an Employee Table, an Course table, and an relation-table inbetween.
Now I want that the user can select out of the course table his courses in a dialog form.
That means that the underlying table for my continous form inside the dialog is the course table.
I want a checkbox in every row which indicates if the course is selected or not.
As I read it is not possible, to add an unbound checkbox, because they are just copies, and a select click would select all of them.
The solution would be to add an yes/no field to the underlying table courses.
But here I have the problem as I understand the matter, because I have several users using the database at the same time, that the underlying table will be updated if I click one checkbox and this update will select the value for all users which are using the dialog form concurrently, what I dont want.
So my question is, is there another solution to get a working checkbox per row in a multi user access database.
There are two solutions which I could imagine:
1) The underlying table will be the relation table and in this every possible combination between employee and course will be saved together with a yes/no field. (but that would be from a data view point quite horrible)
2) If the changes to a checkbox would not be directly written back to the database table, I could discard them on saving and manually insert the relation records in the relation table. (Is that possible?)
Thanks for any solution proposals
I see two good approaches:
1) This assumes that your database is split in a network backend + each user has a local frontend. This is the recommended setup for multi-user.
The frontend has a local table with Course_ID and a yes/no column.
A join of this local table with the Course table is the recordsource for your continuous form.
On loading, you copy the course ids into the local table, and set the existing relations to True.
On saving, you update the relation table.
2) Use a ListView control instead of a continuous form. It has inbuilt checkboxes. Loading and saving is done with a VBA loop.
Based on your description I assume your form has a LEFT/RIGHT JOIN in its data source where some ID field is null if the specific Course/Employee combination does not exists in your relation table. Let's call it LinkID. Then your checkbox should be something like =NOT ISNULL(LinkID). While you will not be able to use the OnClick event for the user to check/uncheck this way, you can use the onMouseDown event to see if the user clicked the checkbox and take action accordingly.
That way you don't need an "all combinations" relations table, no temporary table and no Yes/No field. If a record with the Course/Employee combination exists the box is checked, if it does not exists, it is not checked. Adding and removing courses is done by adding and deleting records from the relation table.
Have a look at this How to use unbound checkbox in a Continuous Subform - MS Access. A class that binds an unbound checkbox. Better than listbox, because you have a form with all its benefits (sort, filter, edit, append).

Access 03 Parent and Child linkage issue

I have an Access database (2003 Access) that has a main form linked to a table (tblClientMaster) and a series of subforms. TblClientMaster has a series of unique client names. You can then click on each subform (there are labels with each name that can be clicked on which will open the subforms) and they should filter based on the client you have selected on the main form. I can't filter the subforms based on additional criteria, but I've basically given up on this for now (filter the subform results based on the value of a field on the main form along with an additional parameter, like product name. Every attempt I've made has utterly failed and posting questions on here about it generated no responses, so I've abandoned this for now.)
I am focusing on getting a single subform to work right now (fsubBenCalcs). Each record of the tblBenCalcs has the name of the client which matches the client name listed on tblClientMaster. When you click the BenCalcs subform, it filters the results by client and you can cycle through each record that exists with the same client name. (for instance, Company ABC has 25 calculations that have been completed. Once you select Company ABC, you can click on the BenCalcs subform and it will display the first record and you can cycle through the other 24) However, when I open the main form, it asks me to enter the Parameter value "tblCalculations.Forms!frmMain!ClientName".
First, I don't understand why it is looking for tblCalculations.Forms when tblCalculations is a stand-alone table containing the data for fsubBenCalcs. Second, when I load the main form, it should be completely independent of any value on fsubBenCalcs. Only when I load fsubBenCalcs should it look to the main form for the name of the client.
On the Subform/Subreport (when I go into properties on the main form and find the BenCalcs subform) it has the fields "Link Child Fields" and "Link Master Fields". For these, I put [Forms]![frmMain]![ClientName] for Link Child Fields. For Link Master Fields I just have ClientName.
I have to imagine something is wrong in here, but I haven't been able to come up with the correct way to link these forms. I would appreciate any help or guidance on this. I hope I was clear enough in my description.
Subforms (child) must link to the main form (parent). Subforms are not designed to refer to each other in a partent-child relationship.
You can hack this as follows:
Put a text-box on the main-form (i.e., NOT any of the sub-forms) with the following control source:
=[subForm_1].[Form]![FieldYouWantToLinkBy]
Then, in your "child" sub-form, use the parent-child linking fields to refer to this textbox.

Suggestion and auto-complete in form with one-to-many relationship in Access

I am trying to make a form for a very typical scenario: a customer makes an order. The customer might be new or returning. I have created an Access database with two tables: Job and Customer (linked by the primary key 'customer no'). The form I wish to create looks like this:
The customer table data is highlighted.
When the customer's name is beginning to be typed in, I want to see an updating list suggesting possible customer matches. If the customer happens to be returning, I can click on one of the drop-down options and have all other customer fields auto-complete.
What is the best way to create such a form?
I tried to achieve this using a comboBox and some code. However, if I use this method, the comboBox does not allow me to enter a customer name which isn't already in the customer's table. So I can't enter new customer details.
Ideally, this auto-complete/suggestion should work for all customer fields, such as phone number (in case the phone number is the only know customer info).
You could use a combobox which has LimitToList set to false, allowing entry of data not already defined in the combobox's rowsource; With this approach you would define a not-in-list event handler for the combobox to open a popup form for adding a new customer, ideally pre-initialised with the customer name just entered, and when data is saved in that form, control returns to this form, requeries the combobox (as it's contained data is now out of date), re-locks the customer just added, and fires it's after update event to display all the relevant customer-related fields appearing on this form.
However whether this is appropriate or not depends to some extent on the quantity of data that you have. If you've more than say 10000 customers in the database, I'd recommend instead having an elipsis (...) button beside customer name which opens a popup search screen, and provides whatever search options seem best (name, number, city, etc) for the entity being searched, a textbox, and find + add buttons; With huge data quantities you might also want to provide a means to prevent searching for matches (especially by multiple users across a busy network) where there is less than say 4 characters in the textbox, to improve performance.
You'd then use the text_changed event on the textbox to retrieve the data in the database which starts with the text currently existing in the textbox, and display this in a datasheet; The user can then either click Find or double-click the datasheet to select a customer which you then return to the calling form, probably by either a call to a public sub, or setting a tag value on that form - or click Add to add a new customer and invoke logic similar to the above.

textbox in continuous form populated from different table

I have a continuous form in an access 2010 database that outputs a separate row of data for each customer from a customers_table. The continuous form is for data display only, and no data entry or editing is allowed. One of the textboxes on the continuous form is populated with data that was entered using a combobox in a different form used for data entry. In the textbox on the continuous form, enabled is set to no, and locked is set to yes, so that the textbox is not editable in the continuous form. However, in the separate data entry form, the combobox entered the id for the selection the user chose, instead of entering the text. Therefore, in the continuous form, only an id number is shown, when the user needs to see the text of the specific option which is encoded in that id number.
I think I want to keep the id in the customers data table, in order to retain freedom to make subtle changes in the combobox options later.
So how do I modify the textbox in the continuous form to populate with the textual value associated with the id number? This would seem to involve some sort of SQL like:
"Select textValue FROM comboboxsource_table WHERE comboboxsource_table.ID=textbox.Text"
However, I have no idea where to put this in the Access GUI. The Control Source field in the Data tab of the property sheet for the textbox does not seem to allow this sort of syntax.
If you're not editing the data, put a query behind the form instead of a table. Then, just pull the field you need into the query and VOILA! Problem solved. :o)

Changing Record of Subform in MS Access

I have a form that contains 4 subforms. The first subform gets data based on a selection in a combo box on the main form. The second subform gets data based on the first subform, and the third and fourth subforms get data based on the first.
It's a database contain information on research grants. I want to be able to pull up certain data based on a person's ID (multiple records to a person) or by the title of the grant. Names are working fine, but searching by title is giving me a hard time.
I've tried setting first subform's Record Source with a .RecordSource ="" line, but nothing updates at all when the code runs (the code is in the AfterUpdate event of the combo box containing grant titles). This one has me sort of stuck; I'm not sure if the dependencies among my forms have something to do with it.
Did you put a Form.Refresh in after you updated the recordsource?