I have an Access form with (continuous) subform and one of the combobox fields on the subform is populated with data depending on the value of another field.
For this I use the following in the Data Row Source:
SELECT VendorName FROM VendorsPerAction WHERE (Action= Forms![LocalSubformActions]![fldAction]) UNION SELECT distinct null FROM VendorsPerAction ORDER BY VendorName;
This works fine when I test the form outside the mainform. But when I test this as part of the mainform Access keeps asking me for the parameter. I tried changing it into:
(Action= Forms![LocalRequest].[LocalSubformActions]![fldAction])
and many other variations but I keep getting the parameter question.
Is there anyone who knows what I should use? Thank you!
Probably
Forms![LocalRequest].[LocalSubformActions].Form![fldAction]
(assuming the subform control has the same name as the subform)
See Refer to Form and Subform properties and controls
--> Forms!Mainform!Subform1.Form!ControlName
Related
This time I'm trying to work on an MS Access application. I have a split form populated using a SQL query. Now I want to filter this form using a combobox which is located in the header of the form. This CB is also populated with a SQL query:
SELECT DISTINCT [ConsultQ].[ClientName] FROM ConsultQ;
I have added an embedded query to this Combobox which should filter the form. The values shown in the Combobox are correct. But when I select a value from the box a popup show which asks me for input.
The ApplyFilter action is set to:
So, apparently, the ApplyFilter action cannot retrieve the selected value of the Combobox. What am I doing wrong here?
When I enter a name in the input box, the filter is applied correctly. So the filter works, but I cannot set the filter using the selected combobox value.
It must be something simple, but I cannot find it.
I'm using MS Access Office 365 version.
Remove the [Text] property. You want [Value] and [Value] is the default so doesn't have to be explicitly referenced.
Also need full path reference to combobox.
Forms!yourformName!cboClient
However, really should use ClientID to filter records. If the combobox has ClientID as first column and first column is set as the BoundColumn, then combobox value is ClientID, not ClientName.
Sorry in advance for the long description, but it seemed like the prudent course of action.
I am having a problem getting a combo box to correctly populate a text field in a subform.
Based on surfing the web and some helpful guidance on adding VBA to forms earlier this week here is what I tried.
I have created a table tblPgo showing several probabilities of a project proceeding and a corresponding descriptions.
I have a second table tblDetails containing information about the items we are selling.
These two tables interact in a subform tblDetals subform.
I added a combo box cmbPgoValue to the subform. The combo box gets its data from tblPgo
Control Source is Pgo
Row Source is SELECT [tblPgo].[PgoID], [tblPgo].[Pgo], [tblPgo].[PgoDescription] FROM tblPgo ORDER BY [Pgo];
The Row Source syntax was created by the combo box wizard.
In the subform, I created an unbound text box called Pgo Description to receive the PgoDecription text corresponding to the selected Pgo value from the combo box.
cmbPgoValue has the following After Update Event code
Private Sub cmbPgoValue_AfterUpdate()
Me.PgoDescription = Me.cmbPgoValue.Column(2)
End Sub
When I use the combo box to select a Pgo value, the correct Pgo Description populates the current record and the record below it. When I try completing the incorrectly populated record, I get an error about duplicating indexes, etc.
I've tried bounding the text box, but it does not seem to help.
Thanks in advance.
That is to be expected with UNBOUND textbox. There is only the one Description textbox so all records will show the same info. Should not be duplicating this info into tblDetails. Instead of VBA, just have expression in textbox ControlSource:
=cmbPgoValue.Column(2)
I've been searching this issue on Microsoft, Stackoverflow, techinthenet.com and several others, with no real solution that I can find.
I am trying to get two comboboxes (cboCourse and cboVols) to populate based on the selection of cboTrainee_Name. The code for the first combobox is:
SELECT DISTINCT [qryBooks].[PName] FROM qryBooks WHERE qryBooks.Complete=No ORDER BY [qryBooks].[PName];
Everywhere I've searched gives assistance and samples to populate the first combobox, then the second combobox based upon what is selected in the first. I need both cboCourse and cboVols to populate based on the result of the same query. What I have so far is:
Private Sub cboTrainee_Name_AfterUpdate()
cboCourse.RowSource = "SELECT DISTINCT [qryBooks].[Book] FROM qryBooks WHERE [qryBooks].[PName]=[Forms]![frmIntro]![cboTrainee_Name] ORDER BY [qryBooks].[Book];"
cboVol.RowSource = "SELECT DISTINCT [qryBooks].[Vols] FROM qryBooks WHERE [qryBooks].[PName]=[Forms]![frmIntro]![cboTrainee_Name] ORDER BY [qryBooks].[Vols];"
End Sub
This works for cboCourse, but cboVols will not populate. I know there has to be a simple explanation. Any suggestions?
ADDED! I used SELECT DISTINCT because each column in the query contains multiple instances of the same data.
I don't see any problems with your SQL.
You might need to call the Requery method on both combo boxes to get them to refresh after cboTrainee_Name is changed:
cboCourse.Requery
cboVol.Requery
Note that you don't have to set the RowSource property in code for this to work. You should be able to plug in your SQL statements as is in the RowSource property and just the Requery method on the dependent combo boxes in the AfterUpdate event of your cboTrainee_Name combo box.
I am pretty much a newbie to using VBA in Access and I'm having trouble with something that seems like it should be quite simple.
I have two listboxes (called LB1_ID and LB2_ID) on my form (MainForm) that I want to list related IDs from their respective Row Sources. I need LB2 to be populated based on the selection in LB1. They both have Row Sources from the same Table (Table1) and it is a many to many relationship of Requirement IDs ("Req ID1" and "Req ID2"). My current form, which is not working, has the Row Source of LB1 as:
SELECT Table1.ID, Table1.[Req ID1] FROM Table1 ORDER BY Table1.ID;
and the Row Source of LB2 as:
SELECT Table1.ID, Table1.[Req ID2] FROM Table1 WHERE ([Forms]![MainForm]![LB1_ID]=Table1.[Req ID1]);
When I make a selection in LB1, nothing happens in LB2. The column widths are formatted correctly and I can get it to work if I use Me.[Forms]![MainForm]![LB1_ID] but I have to type out the LB1 selection manually in a popup box if I use that.
What am I missing?
If your listbox is multi-select, you cannot use a simple form reference as query criteria. If it is not multi-select, keep in mind that its value may be a hidden column (usually an ID field), so there are two possible issues and solutions:
Possible Issues:
Single-Select listbox has an ID field that is hidden (column width = 0") and you are matching it to the wrong field in your table. To check the output of the listbox, open the VBE and type ?[Forms]![MainForm]![LB1_ID] into the immediate window and press enter when your form is open in form view and a row is selected in LB1_ID. If the returned line is what you expect, then the problem must be elsewhere.
Multi-Select listbox property is enabled. In this case, your query will not work, because the listbox will only return Null. You will need to write some VBA to loop through the rows and figure out which ones are selected, which is a bit of a pain. Ultimately you'll build some code that will alter your query with the specific criteria for each selected row. Instead of explaining here, take a look at this article for a tutorial.
The .Requery method is still important to put in the AfterUpdate event of your first listbox to refresh the second.
Your query seems to work, but you need to refresh your listbox2 whenever you make selection into listbox1, so if both listbox are in the same form add this event handler :
Private sub LB1_ID_Change()
Me.LB2_ID.Requery
End sub
Without this, your listbox2 will only get populated once on load based on the initial value of listbox1.
Also, if you have not already done it, I would recommend to add your listbox1 control as a parameter into your listbox2 query (in query builder, right click -> parameters).
I have a list control on my form. The values of this list come from a query. the Row source of the List is like this:
SELECT tb_lable_Daten.name
FROM tb_lable_Daten;
and Control Source of the list is name
I want if the user change the value of the List(with mouse, key down,...) the value of controls( 3 Texts) in Sub form changes too. The query in Sub form should be:
SELECT XValue, YValue, Wert
FROM tb_DCM_Daten
WHERE (tb_DCM_Daten.name)=name); // It is List value
I put this query on Subforms recordsource but that doesnt work.
Could you please tell me how can I do that?
I know I'm coming in three years late. However for anyone that comes here... The .Requery() is needed but the main issue is that for the Record Source for the field in the subform it should read =[FORMS]![MainForm]![ListField] where mainform = the name of the parent form and listfield = the name of the list field on the parent form. In addition having the .Requery() on update would push the new value to the subform.