ms-Access Not using combo box display values as the lookup value - vba

NOTE
I significantly edited my original post to include more relevant information and removed insignificant information. Some of the comments are based on the information removed, but the integrity of the original question is still intact and the comments are still relevant and useful.
In my database I have a table tblStandards that has a list of compound names with their associated fields.
I created a form to generate a subform which only populates compound names and their data when you select a solution mixture (I called these "handles"). I am using this subform as a means of generating a "Location Finder" of all the respective compounds associated with that solution mixture "handle". The issue is some compounds are used in multiple different mixtures, thus having multiple "handles". I have included a cascading combo box as recommended by #June7, but I am running into an issue with the last combo box filter.
I don’t want to have a separate field attached to my tblStandards with the combo box display value ("handle") just to filter my table (which is what I have done in the past). Using combo box display value field in my table works but it is limited and I wish to make it more modular. I have a second table tblComboBox which has three fields; [Compound Name], [Standard_InternalStd], and [Cal_QC_Handle].
I have the cascading combo box working, except for last filter. I think I found a round-about way to filter based on my tables. I am using an After_Update event with the FilterOn function to filter a TempSubform which is filtering the tblComboBox based on matching the [Cal_QC_Handle] to the cboxSecondChoice, then using TempSubform![Compound Names] field as a second FilterOn function for my MainSubform.
My code is working, but the second FilterOn is only using the first Compound Name from my TempSubform to filter MainSubform. I want to filter based on all the rows in my Tempsubform.[Compound Name]. I think my issue is in my " & Me.Temsubform![Compound Name] &" block of code.
Private Sub cboxSecondChoice_AfterUpdate()
Dim Filter_Tempsubform As String
Filter_Tempsubform = "[Cal_QC_Handle] ='" & Me.cboxSecondChoice & "'"
Forms![Standards_Form]![TempSubform].Form.FilterOn = False
Forms![Standards_Form]![TempSubform].Form.Filter = Filter_Tempsubform
Forms![Standards_Form]![TempSubform].Form.FilterOn = True
Dim Filter_MainSubform As String
Filter_MainSubform = "[Compound Name] = '" & Me.TempSubform![Compound Name] & "'"
Forms![Standards_Form]![MainSubform].Form.FilterOn = False
Forms![Standards_Form]![MainSubform].Form.Filter = Filter_MainSubform
Forms![Standards_Form]![MainSubform].Form.FilterOn = True
End Sub
The issue is the filter is only using one Compound Name (the first on the list) to filter. I need the filter to use all the Compound Names from the newly filtered TempSubform. Apologies if this is a very convoluted approach. Every example that I have seen so far always has the combo box value embedded in the table that they are filtering, which is something I wish to avoid.
UPDATE
I have abandoned my 1st attempt (the double FilterOn function with a temporary Subform) and I have a working form! I had to modify my tblStandards to include a new field which contained values from my final combobox selection (which I wanted to circumvent initially due to my perceived limitations of this design). The new Form-Handle field on my table is a string with multiple single "handles" which I use if the final combobox selection (only a single "handle" can be selected) is in the subform using the wildcard "Like *". Each one of these "handles" corresponds to a solution mixture which is a specific list of compounds.
This solution allows me to have a single compound used to make multiple different solutions, and if you select any of these solutions to make from the dropdown combo box the compound will be returned. I think this is the simplest solution to my issue and I might have just been too stubborn looking for a over-complicated solution.
I modified code from Allen Browne's ms-Access "Filter a Form on a Field in a Subform"
Relationships (All)
Form with cascading comboboxes and filter button
Working code

As #June7 said, cascading ComboBoxes (or ListBoxes) are the standard UI design for multistage filtering of data tables. If I have the available form real estate, I prefer cascading ListBoxes over ComboBoxes, because of the visual cues they provide. For example, look at how Digi-Key does it. Problems with cascading ComboBoxes have been questioned to death here. Boxes which filter data, list or combo, are usually unbound, and should not be simultaneously used to update data. Their sole purpose is to display item choices, select an item, and pass it's value to the next filter.
I'm linking below to a few tutorials, which require little to no VBA code. The 3rd tutorial filters "plants and animals, categorized by their taxonomic rank", which is a similar case to filtering chemical compounds. The 4th is one of my previous answers to a similar question.
Microsoft Access: How to Create Cascading Combo Boxes
Access 2016 - How to Make a City/State Selector (Cascading Combo
Boxes)
Creating Cascading Combo Boxes and List Boxes on Microsoft Access
Forms
Creating Cascading Comboxes in VBA code using RowSource

Related

MS Access: Dependent drop down combobox in Split form without affecting the rest? [duplicate]

This question already has an answer here:
How to query combo box of only current record/row in Access data entry form?
(1 answer)
Closed 1 year ago.
I am trying to make a dependent drop down work with my database here but it is giving me a hard time for different reasons that I will explain.
This is what I have:
A form called "tblOTS" (split form based on an actual "tblOTS" table):
As well as a table called "tblAlphaCode":
When looking at the property sheet for the "Alpha Code" combobox (actually called "strOTSAlphaCode") on my tblOTS form, this is what I have:
The current SQL statement under "Row Source" for this strOTSAlphaCode is:
SELECT tblAlphaCode.strAlphaCode, tblAlphaCode.strCategory,
tblAlphaCode.ID, tblAlphaCode.numSortingOrder
FROM tblAlphaCode
ORDER BY tblAlphaCode.strCategory, tblAlphaCode.numSortingOrder;
Basically, when user select an Alpha code in the drop down from "tblOTS" form, it adds the ID of the tblAlphaCodes into the actual tblOTS record.
My goal is to have the user select first a "Category" (here FASTENERS/HARDWARE ...) when adding/modifying an OTS record, and then have the "Alpha Code" drop down dependent on what category was just selected.
I first tried to changed the SQL statement using a WHERE condition on the category field, based on the form category field itself:
SELECT tblAlphaCode.strAlphaCode, tblAlphaCode.strCategory, tblAlphaCode.ID, tblAlphaCode.numSortingOrder
FROM tblAlphaCode
WHERE (((tblAlphaCode.strCategory)=[Forms]![tblOTS]![strOTSCategory]))
ORDER BY tblAlphaCode.strCategory, tblAlphaCode.numSortingOrder;
And created a strOTSAlphaCode.requery in my Form_Current event to update it everytime.
However, it affects the whole form itself as my control source is directly affected by my Row Source in this instance, and the form looks like this:
You can see that the drop down is working beautifully, however, all the fields that do not have the same category as the current record that I work on (FASTENER <> HARDWARE here), are missing their Alpha code (the second record is missing "O-RING" compared to the first picture from this post); this behavior is problematic!
I tried to find workarounds by changing strOTSAlphaCode into a simple text box only containing the Alpha Code ID, added an unbound text box on top with dlookup function to find the actual alpha code related to this ID, and an unbound combobox in between with the exact same SQL statement inside the Row Source Property, that would update the strOTSAlphaCode with some VBA ... not ideal right?? Ahaha. This is why I believe there is a simpler way that I am not aware of, but also I would like to use a "search as you type" code for this combobox later on and this solution was making it very difficult.
How can I make this work? I believe the answer is a simple/different SQL statement to put in my Row Source property, that is probably something related to some type of JOIN statement? Or something else? I expect to write some VBA code to make all of this work flawlessly, but I want to make sure that I have the right SQL statement first.
Thank you June7;
Yes, the link you gave me ( this link ) states 2 solutions, and the second one is the one that I talked about when describing my problem:
for forms in Continuous or Datasheet view, include lookup table in form RecordSource, bind a textbox to descriptive field from lookup
table, position textbox on top of combobox, set textbox as Locked Yes
and TabStop No
So I guess, the answer is that I MUST have a textbox with dlookup setup for my case; I put it on "locked" so that if the user wants to change it by typing in it, he will first have to select the arrow. This will work with what I wanted to do
Cheers,

MS Access sub-form data entry locked on inserting SQL

I am not able to encode any entries to the Sub-form data grid on the Main form when I inserted the following SQL field. If I remove this column, the system allows me to the new data record creation. Can anyone look into this issue please!
Advance Payment Balance:
(SELECT SUM(NZ(T1.AdvancePayment,0)-
NZ(([GrossInv-WorksCertified-61110]*
[SubCon-BasicInfo].[Advance-409130-%]/100),0))
FROM [InvoiceMaster] AS T1
WHERE T1.[SubConName]=[InvoiceMaster].[SubconName]
AND T1.[ID]<=[InvoiceMaster].[ID])
Using calculations in a query make the underlying recordset not updateable.
See this question for an excellent list why queries (and forms based on them) sometimes are not updateable.
The proper way to include calculations on a datasheet form is to open it in design view, add a new text box control to them, and set the controls control source equal to an = equal sign followed by your calculation.
You also will need to rewrite the subquery to a domain aggregate or use a combo box to use a query.
Rewrite example:
DSUM("NZ(InvoiceMaster.AdvancePayment,0)- NZ(([GrossInv-WorksCertified-61110]*[SubCon-BasicInfo].[Advance-409130-%]/100),0)", "InvoiceMaster", "[SubConName] = """ & [InvoiceMaster].[SubconName] & """ AND ID = " & [InvoiceMaster].[ID])

Combo Box on form to filter table I imported into Access from Excel

I have been searching for a couple of hours but I can only see examples of combo boxes on forms filtering tables that are based from queries.
My table (which I have put on a subForm) is from a static datasheet that I imported into Access from Excel so therefore does not come from a query.
I want to use a combobox (or a textbox) so that the user can enter in the reference number and it will filter the table (rather than using the filters already provided (as they just get confused))
Is this even possible? I should add, the reason why I want the table showing (and not a query from it) is that I want the user to be able to edit the table once they have found the reference number they are looking for.
Any help would be much appreciated.
You can use the form's filter method to programatically filter the rows. careful though, as you probably are going to need a mechanism to remove the filter, like a separate button as it won't be obvious. OR, you may still want to keep the form's "Navigation Buttons" property to true. this would then have allow the user to see that the rows are filtered, and also allow them to remove the filter.
Use the form's filter methods to filter. so say they want to filter on a field called "value1" with value of 1, it would be like this. if your filter condition is text, then use single qoutes around them.
Me.Filter = "[value1] = 1"
Me.FilterOn = True
I think your question is more about a ComboBox updating a view, right. I don't think this really has anything to do with Excel, right. If this is correct, please see the link below.
http://www.fontstuff.com/access/acctut17.htm
Also, see this.
http://www.fontstuff.com/access/acctut18.htm

How to create multiple connected search combo boxes to filter a form?

I have a form with 10 columns, and for 5 of them (Project_Phase, Contract, Design_DPM, AMM/UCC, 1_or_2 stat) I want to add connected drop list combo boxes to filter the records and display data as selected in the combo boxes.
I know how to make multiple drop list combo boxes that filter the whole form based on the selection of one value from one column. For example, "Contract" combo box has options: signed, not signed. If I select "signed" it will display all the records that have "signed". and If I filter another column it will cancel the previous filter and display records relevant only to that selection from that column.
But what I want is the ability to filter using any number of filtering options from the 5 columns I mentioned. For example, if I want to see the records that are ("signed" under "Contract") and in ("proposal" under "Project_Phase") and ("a certain DPM" under "Design_DPM"). And after filtering I want to be able to clear the filters and see all the records again, as I am using this form to display all my records for users. I do not want it to be cascaded, as I might want to filter using only one column or more or all. And I do not want it to be a query or use the basic filtering in datasheet view.
Sorry for the lengthy explanation, if something is not clear I will explain further. Thank you for your efforts.
Here is one way to implement a form filter using multiple comboboxes.
Create a table named 'tblWildcard'; one field named 'Wildcard', save the table.
Enter one record with an asterisk as the value
Create the queries for your comboboxes like:
SELECT DISTINCT Table1.flda
FROM Table1
ORDER BY Table1.flda
UNION Select wildcard from tblwildcard
Save a query like the following SQL to be the Row Source for your form (i.e. qryFormA):
SELECT Table1.Flda, Table1.Fldb, Table1.Fldb
FROM Table1
WHERE (((Table1.Flda) Like [Forms]![frmForm1]![cboFlda])
AND ((Table1.Fldb) Like [Forms]![frmForm1]![cboFldb])
AND ((Table1.Fldc) Like [Forms]![frmForm1]![cboFldc]))
In the After Update event for each combobox add the following code:
Me.Recordsource = "qryFormA"
Sometimes the 'Me.Rowsource.' may not work when changes are made (weird issue!). If so, do the following:
Application.Echo False
Me.RecordSource = vbNullString
Me.RecordSource = "rowVwFilter25"
Application.Echo True
Finally, if a multi-user environment, and people may be adding records that will need to be included in your comboboxes, use the combobox Before Update event and add the following code:
Me.cboFldA.Requery
My question is answered. I found exactly what I wanted here link
Thanks for the help everyone

Access form - how to make text field have a control source from a SQL query?

Background
I have two tables:
Projects
EmployeeID
Employee
EmployeeID
Name
I have a query I am basing a form on containing, among other items:
SELECT e.Name FROM Projects p JOIN Employee e ON e.EmployeeID=p.EmployeeID
When I make a form in Access based on this query, I can very easily display e.Name on my form because it is joined from the query.
My real example is of course considerably more complicated than this simple example. The above works fine for read-only queries and scales well. However I would like to use a Splitform view and this becomes very slow with many joins for even small numbers of recordsets. Considering a large percentage of my joins are simple like the above, I am hoping for a way to remove as many as possible.
On the form, e.Name will be read only and not be update-able.
Similar question
In this question I am able to successfully change a combo-box into a lookup. The accepted answer allows a combo box to control Projects.EmployeeID by displaying Employee.Name field in the combo box.
Possible work-arounds
I know one way I could do this is use a combo-box but disable it. This would look a bit weird since it'd have the drop down selector but not be selectable.
Alternatively, I could make it a completely unbound field and write VBA code to update the form each time the recordset changes by running quick queries, getting the text value I am searching for, and updating a label accordingly.
Neither of these are overly appealing, however.
Question
How can I display a single text field on an Access split-form which is the result of a very simple query lookup, based on an ID from the main table field?
You can use Dlookup to return this reference very simply
Construct a Dlookup formula like:
=DLookUp("Name", "Employee", "EmployeeID =" & "[EmployeeID]"
and use this as the ControlSource for the textbox.
Some notes:
The & is important as it binds the formula to the single record displayed on the form
[EmployeeID] refers to the current record displayed on the form. This assumes that "EmployeeID" is included in the query for the form, whether bound to the Projects table or included in the query