Changing Record of Subform in MS Access - 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?

Related

MS Access get number of sub rows in datasheet

I have a little problem here. I've a database with one table for Users and one for changes in progress for these users. They are in a 1:n relationship (one user can have many changes but one change only affects one user).
I output my users in datasheet view and have the changes in by standard collapsed subrows of this datasheet. The user shall be able to order the users by the number of ongoing changes matching the filters in this sub-form. Therefore i have to get the number of rows in this form.
in the subform i have a field called "Anzahl" (german for count) representing the number of elements currently shown in the sub-form and i have a field called SubFormAnzahl in the parent datasheet.
Now i try to access this field via
=[Changes_Subfrom].[Form].[Anzahl]
and i am getting a #Name? error.
Why does this happen and how can i prevent it?
With main form set as datasheet, it can't see subform textbox until subdatasheet is expanded, then the calc shows. If you want to keep main form as datasheet, options are:
set main form SubdatasheetExpanded property to yes.
DCount() domain aggregate function on main form - expression in query used as RecordSource or in textbox and must use same filter criteria applied to subform
DCount("*", "Changes", "UserID=" & [ID])
Otherwise, works with main form in Single view.

How Do I Make a Subform Controlled by Report (Which is Controlled by a Query) Update After Records Are Added?

I recently took a duty position that requires me to track our administrative actions. Previously, the office had tracked them on an Excel spreadsheet, and the historical data was corrupted/missing. So I have built a database in Access 2010. I designed the database to display a main form that provides an overview of each action, but decided to require most of the data to be added or updated on specific data entry forms. My question relates to two subforms on the main form that I cannot get to update after data is entered into the tables. Here are specifics:
1) The main form is the case detail form, and each case has a unique case ID number that links most of the forms and tables.
2) The Case Detail Form has two subforms. One displays the names of the people involved in the case (this is the Subject Subform). The other displays the case history entries (this is the Case History Subform).
3) Both of the subforms are supposed to work the same way. Each is populated by a report which displays the information in its corresponding Subform. In turn, the reports underlying each Subform are based on a query that selects the records to display based in the case number.
4) New data for the subforms cannot be entered on the Case Details Form. Instead, the user can press a command button which launches a separate form that allows the user to enter either subject details or to enter a case history update. Once the user enters the data, he or she clicks A Save Record button, which saves the record and closes the form window. Everything seems to work fine up to this point.
5) However, I've now been working on this project for two weeks (as time permits), and I am still not able to make the two subforms update automatically. If it's a new case record, the user can make the Subforms update by using the navigation arrows to leave the main Case Details Form and then returning to it. If it's an established case record, a refresh button that I have added to the main Case Details form will cause the two subforms to update.
As I've tried to make this work, I've tried a number of approaches that I've found on various boards. Right now, I have:
A) The Subject data entry form has a Me.Requery statement in After Insert Event Procedure
B) The Subject data entry form has a SaveRecord and a CloseWindow command that are executed when the Save Record Button On Click event is triggered.
C) The main Case Detail Form has a executes a Me.Case_Subjects.Form.Requery when the GotFocus Event Procedure is executed.
I apologize for the lengthy question and explanation. I'm an Army officer and a little out of my depth with this. I would greatly appreciate any help anyone might be able to offer.
Best regards!
I'm not sure having understood everything but I try to give you some suggestions about what to try.
If I'm not wrong both form and subforms have the case ID as field so when you created the report you should have put them in "link" by the wizard (you can set it manually after but it's a bit more tricky).
Did you do this? This makes the form / subforms update when you navigate them.
Please note that there must be a relation between the underlaying tables to guarantee that the reports / forms moves together!
This applies to the query too, just remember to include the ID field int the queries.
If you don't want to see the ID (in case you use an autonumbering id) you can set it Not Visible.
In case you don't want to link the two tables with a relation there is another solution but it's a bit more tricky and, if it's not your case, I don't want to make confusion.
Let me know if you solved.
Bye
Firstly, the line Me.Requery should be on the After Update event, not the After Insert event. Secondly, you will then need to change Me.Requery to Me.[insertsubformname].Requery.
As the user above said, you will need to ensure that you have created your database relationships properly, however if you used the Insert Subform, it should've asked you what you wish to use as your link between the forms.

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.

Parameters in rowsource query

I have a combobox query that uses parameters from a parent item. When I first load the form the combobox is empty, if I go to design view and return to form view the combobox is populated with the correct items.
While searching for the cause of this I decided to create an extra text field that retrieves the same data from the same parent item. On the first launch that textbox is populated while the combobox remains empty.
My last step was to change the combobox query parameter to refer to the newly created textbox. After that the previously working textbox started out empty as well and became populated after going to design view and back.
My hypothesis - the query tries to retrieve the parameters before the text fields are filled. Keep in mind I have reversed loading order of main-form and sub-form as explained here.
I don't know what to google for any more
You can requery the combo in the current event of the main form like so:
Me.Subform1.Form.MyCombo.Requery

Selecting a record in Access Subform

I have a form in Access 2003 that contains 2 subforms. The first is in datasheet view and is only 2 fields, SiteID and SiteName, so a list of many sites for one record in the parent form. The second subform is the same datasource as the first, but in single form view, so it shows all the site fields for one site in a single form. The idea being that I have a list of the site names on the left and I want to then click on one and have its OnCurrent event filter the subform on the right to show all the fields in that record (for that site).
This seems like a fairly simple thing to do but I can't figure out what code (docmd.gotorecord?, filter?, programatically change the subforms query and then requery etc) is the best to use... and how to make it actually work.
Any help appreciated.
Have a look at the Customer Orders form in the Northwind sample database (NWind.mdb) that ships with every version of Access or can be downloaded http://www.microsoft.com/downloads/details.aspx?familyid=c6661372-8dbe-422b-8676-c632d66c529c&displaylang=en
I think you will find it does what you want.