Access subform combobox losing query on shut down of DB - vba

I have a cascading combobox in an access subform called Invoice Details, linked to a query (Invoice Query1).
The query pulls MaterialID (Index field), MaterialName, MaterialNumber from the Materials table, and ProtocolID from the Invoices Detail table, with criteria = [forms]![Invoices]![ProtocolID]
If I leave the combobox (Caption Material ID), with the MaterialID visible (ie column >0, the user cannot type the Material Name in, and the MaterialID shows as the value, which is not user friendly.
If I make the column width 0 for the MaterialID field, it works fine until I shut the database down.
On reopening, the combo box retains any previously entered values and the query, but for any new records seems to lose the query altogether and then displays one blank row when selecting the dowpdown on the combo box. Likewise, typing in the values doesn't bring up values in the query either.
How do get Access to retain the query for new records?
I tried requerying the ProtocolID and MaterialID fields on making the subform current, but this did nothing.
Any suggestions?

Related

How do I create a form to input new records into a table that contains only ID values from other tables?

I am new to databases, and I am working on a final project for a class. I have a database with tables related to each other as shown in the diagram here:
I want to create an unbound form that allows a user to add a new purchase to the purchase table by choosing their name, category, and store from data already in these tables, and then add purchase amount and date.
Since the purchases table does not contain the names of people, categories, and stores themselves, only the ID values from these tables' fields, I am struggling with how to create a form that will add the correct IDs into a new record in Purchases based on the names from other tables.
I am wondering if this requires VBA? I have tried playing around with the property sheet on forms, but I am struggling with which properties to address/what to do with them.
If anyone can explain at least a starting process to create this form.
Simply, use combo boxes that query Buyer, Category, and Store table data, hides the primary key ids, but shows the corresponding lookup value to the user. Users will select by the lookup value(s) but really are saving the id to Purchases table as new foreign key id.
As commented above, use a bounded form to map combo boxes to table id fields. Once you place a combo box, the default wizard will guide you on the steps but below are key property sheet attributes (which may be automatically set with wizard but can be manually adjusted later).
Data
Control Source: The column in table (i.e., PurchaseID, BuyerID, CatID, StoreID) to store the user-selected data of combo box (i.e., a form control).
Row source: A distinct SQL query of primary table id and all needed values for human searches. This can be a named table or saved query or an inline SELECT statement.
Row Source Type: If using SQL, Table/Query.
Bound Column: The position of primary table ID in the query resultset to be stored as foreign key Id. Usually this would be the first column.
Format
Column Count: The total number of columns from the recordsource including hidden, bound column.
Column Widths: To hide column from view, set its positional number within semicolon delimiters to zero. Preview form to decide how large to space out other columns. Do note: you can extend beyond the Width of combo box using List Width.
Column Heads: Optional and best if more than one column to guide users on the lookup value content (e.g., First Name, Last Name).
As example, for Category combo box on bounded Purchases table form, consider below property values:
Control Source: CatId
Row Source: SELECT CatId, CatName FROM Category
Row Source Type: Table/Query
Bound Column: 1
Column Count: 2
Column Width: 0";2.5"
Column Heads: No

Make a Subform Combo Box to show results based upon data in its row

MS Access: 2016
I have a subform with two combo boxes. There is a unique ID field on each row (this comes from the form’s SQL). I want to use that ID value in the SQL that populates the Combo Box. However, the combo boxes show results only for the ID from the first row. Is there a way to have access use the ID value from each row?
The first Combo Box on each row has two columns to demonstrate the issue. Here we see the last row combo box using the ID from the first row. I want each combo box to use the ID from its row.
Restating the issue using ID numbers: In the above example the last row combo box displays the results for ID = 138908. It should display the results from ID = 138917. Actually all rows use the ID from the first row (ID = 138908).
Any thoughts on how to pull the ID from the row the combo box is on?
Here is the SQL from the first combo box:
SELECT
codes_bis_vio.violation,
codes_bis_vio_choice.bis_log_id
FROM
codes_bis_vio
INNER JOIN codes_bis_vio_choice ON codes_bis_vio.bis_vio_code = codes_bis_vio_choice.bis_vio_code
WHERE
(
(
(
codes_bis_vio_choice.bis_log_id
)= [Forms] ! [frmDailyPoints] ! [frmDailyPointsPrevBisSub].[Form] ! [ID]
)
);
And the table relationship
And the subform in design mode:
Cannot update unbounded control on each row of a continuous form.
How to loop through the rows of a continuous form in microsoft access and insert value into unbound textbox using vba?
Time to explore other options. Appreciate all the suggested answers!

Access query based on filtered subform only returns first subform record

I have a form with unbound comboboxes that are used to filter a subform based on the combobox value selected by the user. The subform is based on a query that pulls data from the source table. The subform can be filtered on fields in the query. The subform filters the way I want it to when the comboboxes are used. The issue is I want to have a command button that opens a report that displays the currently displayed results of the filtered subform.
I have a report that uses a separate query as the record source. The query criteria for the record ID is set to the record ID field in the subform. The problem I am having is that the query that serves as the record source for the report will only return the first value from the subform.
The SQL statement is below. I have tried removing the WHERE clause and using different join types. If I remove the WHERE clause the query will return all of the records from the source tables regardless of join type. If I add the WHERE clause it only returns the first record in the subform regardless of join type.
SELECT SubrecipientIDSheet.ID, SubrecipientIDSheet.AgencyID, AgencyIDSheet.SubgranteeLegalName, SubrecipientIDSheet.IsAmendment, SubrecipientIDSheet.RecordDate, SubrecipientIDSheet.HasSubrecipient, SubrecipientIDSheet.IsActiveSub, SubrecipientIDSheet.SubrecipientName, SubrecipientIDSheet.SubrepAddress, SubrecipientIDSheet.SubrepEHA, SubrecipientIDSheet.SubrepEHAVet, SubrecipientIDSheet.SubrepERA, SubrecipientIDSheet.SubrepESG, SubrecipientIDSheet.SubrepHSP, SubrecipientIDSheet.SubrepHTBA, SubrecipientIDSheet.SubrepLIHRF, SubrecipientIDSheet.SubrepSHAP, SubrecipientIDSheet.SubrepCounty1, SubrecipientIDSheet.SubrepCounty2, SubrecipientIDSheet.SubrepCounty3, SubrecipientIDSheet.SubrepAuthorizedRepresentative, SubrecipientIDSheet.SubrepRepTitle, SubrecipientIDSheet.SubrepEmail, SubrecipientIDSheet.SubrepPhone, SubrecipientIDSheet.SubrepTargetPop1, SubrecipientIDSheet.SubrepTargetPop2, SubrecipientIDSheet.SubrepTargetPop3, SubrecipientIDSheet.SubrepTargetPop4, SubrecipientIDSheet.SubrepOtherTargetPop, SubrecipientIDSheet.SubrepPrimaryService, SubrecipientIDSheet.SubrepCulturalSpecificPop, SubrecipientIDSheet.SubrepUseHMIS, SubrecipientIDSheet.SubrepHMISSupportPlan, SubrecipientIDSheet.SubrepDataReportMethod, SubrecipientIDSheet.DescripCurrentScope, SubrecipientIDSheet.DescripChangeScop, SubrecipientIDSheet.DescripWhyChange
FROM AgencyIDSheet INNER JOIN SubrecipientIDSheet ON AgencyIDSheet.ID = SubrecipientIDSheet.AgencyID
WHERE (SubrecipientIDSheet.ID) = [Forms]![Subrecipient Information].[Form]![SubrepSubform].[Form]![ID];

Return subform values based on muliple criteria in Access

I need to select one or more values from the same field in subform 1 and display the applicable values in subform 2.
I have done this kind of thing by selecting criteria from multiple fields but not with multiple line-item values from the same field. My first thought was to build a dynamic SQL string to populate subform 2 but just wondering if there is an easier way to do this.
At the moment if I select a line-item in subform 1 (flight itinerary), subform 2 will only show the applicable flight segments for that itinerary. If a customer has more that one flight itinerary for the same trip in subform 1 I need to show all flight segments for the entire trip in subform 2.
Thanks to Lee Mac's suggestion to utilize the IN() function/operator, I was able to feed the IN() function with a subquery string to return the data I need without having to loop through a recordset. Just had to ensure that the subquery only returned values for a single field (in this case the ID field) or it would error out.
I created a function to fill in the Segment numbers in order.

Joining form and subform/appending columns

I have a form, a subform, and 3 tables. The first table is the data in the form, simple stuff like date, and the name of the person entering the form. The second table is the subform which is a list of tasks and a yes/no button next to it stating whether the task has been completed.
I would like the form to fill the third table so that for each observation in the subform, you have the name of the task from the subform, the yes/no button from the subform, plus the date, and name of person from the form. So if there are ten tasks, and one person does them all then I'd want the new table to have ten observations that each has the person's name, the date, the name of the task, and whether it was done. The problem is to join the first two tables into the third would require some common variable to join on and that's not really what I want. It's more like appending columns.
Any ideas on how I can do this?