I have a report with a listbox (which contains a concatenated field)
SELECT tbl_Employee.GID, tbl_Employee.Sname, tbl_Employee.Gname FROM tbl_Employee ORDER BY tbl_Employee.Sname, tbl_Employee.Gname;
I want to select one of the items of this listbox so that the value (GID) is taken over in textbox GID (which is used to fill tbl_Report)
But somehow I can't select Items in the ListBox in the report,
Anyone have a clue to why this is happening?
Overview of used Tables is added below:
This is not possible. Selectable Listboxes are not meant for reports, but you can use it in forms.
Related
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 am working with two multi select combo boxes on an Access 2007 form. The first multi select combo box is a list of Diagnoses called cboPatDX. After the user selects any number of Diagnoses, I want to fill the next field called DXUnclear with just the selections made on cboPatDX. Most of the answers I have found online do not apply to the multi select combo box. Among many options I have tried, this is the latest, but I get a type mismatch error:
Me.cboDXUnclear.RowSource = "SELECT ID, Diagnosis FROM tblOptsWorkingDX WHERE ID = Me.cboPatDX ORDER BY Diagnosis"
Me.cboDXUnclear = Me.cboPatDX.ItemData(0)
I would appreciate any help with this, including other methods to make this work.
Here's two links that might help you:
filter a query based on multiple list boxes in a form
https://bytes.com/topic/access/answers/446193-filtering-query-values-multi-select-list-box
How to a get the value of value selected in a combo-box? I have a combo-box called "cndGetUsage" in a form called "frmStationUsage". How do I get the value in the form and check to see if a value was selected?
This are being referenced from a module called mMainOutputs.
myval = Me.cndGetUsage.Column(1)
or
myval = [Forms]![frmStationUsage]![cndGetUsage].Column(1)
these will tell you what the current value in the box is. the columns are because in access your combo box can have multiple columns. also if you set the bound column then you don't have to specify it.
Where are you populating the list from? It works great if you're using a Select statement, from a table with a unique ID field as a unique key. Your combo box index is zero based. If you have more controls in the form you can use the Recordset Clone and Bookmark statements to move back and forth as you select items from the combo box
I have created form based on query output. I had used three comboboxes and one list box. First combobox gives me list of Dept, selection of Dept on second gives me location of that Dept (distinct), the third gives me (distinct) project from that location, then next is list box who displays the some codes of that project. The problem is I am able to select only one code from that list and get output in Excel.
If I wanted to select two values at a time, how would I do that?
If I select Multi Select from list box property than I am able to select multiple values but I am not getting output.
When a List Box has its Multi Select property set to "None" then you can retrieve the selected value by simply referring to
Me.List0.Value
However, for multi-select List Box controls you need to iterate through the ItemsSelected collection to determine the items that are selected:
Dim ItemIndex As Variant
For Each ItemIndex In Me.List0.ItemsSelected
MsgBox Me.List0.ItemData(ItemIndex)
Next