Getting CurrentRecord from a table in a subform - ms-access

I have a company form that list their basic info with a subform tab that list more company info like contacts, parts and orders. I use a tab control where each tab has a table with basic info about each. I am trying to open another form that has detailed information about the user highlighted row in the table, but cannot figure out how to read which row is selected.
The form is call Customer, the tab form is called tabDetails, the parts tab is caled tabParts and the table that lists all the parts for the company is called tblPartsList.
This is what I thought would work.
ID = Me!tabDetails!tabParts!tblPartsList!CurrentRecord![ID]

The solution that I found to work was just to call the table control.
ID = tblPartsList![ID]
Thanks for everyone's help.

Use the Form property of the subform control.
tabDetails here is the name of the subform control:
ID = Me!tabDetails.Form![ID].Value
or:
ID = Me!tabDetails.Form!tblPartsList.[ID].Value
The form's tabs are only for ordering the controls. They are not containers for these.

You can use ActiveControl property to refer to the control that has the focus at runtime
ID= Screen.ActiveControl.Parent("ID")

Related

Populate a ComboBox with the Result of a Text Box

I have a form in my Access database called:
formAcademyRegister
Inside this form I have a combo box called:
EmployeeCode
This combo box retrieves its data from a table called:
Employees
The primary key on this field is EmployeeID
To make it easier for the user I created a form called formsEmployeeSearch. In this form use some text fields to make it easier to search for the employee using a first name or last name, returing the values to a list box on this form. This list box has three fields:
EmployeeID
FirstName
LastName
All these fields are also populated using the Employees table so there won't be any data type issues.
Below the list box on the search form I have a button called
butUpdateEmployeeID
When the button is clicked, I want the following to happen:
The EmployeeCode combo box in the formAcademyRegister be updated with the employeeID as selected in the list in the formsEmployeeSearch form
The formsEmployeeSearch to be closed
I am comfortable with the process of closing the form, I am however struggling with the code to populate that combo box with the value selected in the list box.
I tried the following:
Me.Form!formAcademyRegister!EmployeeCode = Me!lstEmpSearchResult.Value
But this is not working.
Try the below.
Forms.formAcademyRegister.EmployeeCode.Value = lstEmpSearchResult.Value
DoCmd.Close acForm, Me.Name, acSavePrompt
A couple of notes.
The keyword Me is not required when the code is behind the form itself, but in some situations it makes the code more readable.
The .Value property is default property (where applicable) thus can be omitted. It's best practice to keep it for clarity.
Me.Form is reference to current Form (where code is).
Forms is collection. Assignement to collection item "Collection(ItemNameOrItemIndex)
Forms("formAcademyRegister").cmbEmployeeCode.Value = Me.lstEmpSearchResult

update mainform control with subform filter

I have a subform that is filterable based off a mainform combobox using parent/child links. It should update a textbox on the mainform with the average of a column on the filtered subform, but I haven't figure out how to do that quite yet.
I have tried just typing in
=Avg([columnname]) as well as
=Avg([Emergence %],[frmbestfacility].[Form]). I've also used =DAvg but no luck.
I'm not sure what I'm doing wrong, but here's the setup.
Main form is called "Results Form", the tabbed form on it is called "Tabs", the tab I'm looking at is called "Best Facility" and the form on that is called "frmbestfacility". The column i'm looking at is "Emergence %". Using any of these gets me #Error. What am I doing wrong?
It should be something like:
=Avg([frmbestfacility].[Form]![Emergence %])
If that doesn't work, create a textbox on the subform, txtAvgEmergence, and set its ControlSource to:
=Avg([Emergence %])
Then, on the parent, use the ControlSource:
=[frmbestfacility].[Form]![txtAvgEmergence])
Note, that when you type this in, you may have to use the localized name for Form

Filter combobox dropdown options using textbox value in Access 2013

I have a form in Access with a textbox and a combobox, and need to filter the combobox dropdown options using the value in the textbox. The textbox contains a Category for the choices.
I've done this using
SELECT Options.Choice
FROM Options
WHERE (((Options.Category)=[forms]![FormName]![Text10].Value));
Is there a way to refer to the value in Text10 without explicitly referring to FormName?
I'll need to duplicate this form within the same Access file and changing all combobox row sources for a new form is not feasible. I can't hard code the Category value for each combobox because there are many comboboxes per form, and the value in the textbox will be different on every form. Any help is appreciated.
You can refer to whatever form you're currently on in Access using Screen.ActiveForm. So in your case you'd have:
SELECT Options.Choice
FROM Options
WHERE (((Options.Category)=[Screen].[ActiveForm]![Text10].Value));
As long as the field name stays constant this should work.

How to bind a textbox to linked child field of subform in MS Access?

So I've got form which has a subform which binds to some textbox on the form. Now within the subform how can I get access to the value in the "child field"?
Here is a good manual about referencing.
Okay, I found a solution to my problem: the textbox on the form was some content of the currently selected row of a table. Now I added an event to this form for changes of the row-selection (Form_Current) which calls a method which manually sets the textbox value directly via a column of the selected table-row like this:
[Forms]![MainForm]![SubForm].[Form]![SubSubForm].[Form].SomeTextBox.SetFocus
[Forms]![MainForm]![SubForm].[Form]![SubSubForm].[Form].SomeTextBox = [Forms]![MainForm]![SubForm].[Form]![SubSubForm].[Form]![SubSubFormTable].[Form]![NeededColumn]
When you link the subform inside Form the filter will work automatically just add the field belong to the child field(ChiledTable). if this not what you mean provide sample of DB.

how to add contents of list box to field in table?

I have a form which contains listbox which will contains links of attachment when ever user use the file dialog. Is there a way to have a field in the corresponding table to contain all the links.
you need to create a new table in the database that will contain the links because there are many links (potentially) for each row.
links (linkid, mainid, linkpath)
mainid is the id of the record that you want these links attached to.
Then in the rowsource property of the listbox put a selects only those links with a mainid of the current record.
In the OnCurrent event of the form you will need a
listbox1.requery
statement