I am writing a query based on a Table which is populated via a Form with several combo boxes. The information is stored in the Table as the Primary Key of the Combobox value which I understand to be correct. However, when I run a query or report based on the Table, I would like to display the Combo box Value rather than the Primary Key ID. Is there a way to do this other than using a Lookup to the combobox in the Table?
Thanks in advance for your help.
JB
It depends on how you have your combo boxes set up. Are they populated from a list in the field or from another table?
If from a list you entered in the table field where the value is stored, you should just store the value.
If they are from a separate table, then set the relationship from the combo lookup table's primary key/ID to a field in the main table that stores the combo selection which should be a number type. In a query, add both your main table and the other table where values for the combo are stored and add the value to your results from the combo value table along with the data from your main table.
It's a little confusing to say you want to query a combobox value, essentially you need to look at the SQL source of the combobox first in order to see where it draws it's values from. You then need to link this back to your query that you are running, as long as there is a common PK/FK between these then you can just perform an INNER JOIN on that.
Related
I'm having a Projects lists Continuous form where the form's Record Source is based upon a table.
I have a requirement to display a field from another table which is linked back to original table using its primary key. The primary key is a AutoNumber field, but when displaying in the form I've used Input mask something like this "TMG/FEA/"0000.
So I made:
a unbound list box
and made the Row source as the query which displays the relevant information from second table
This query was created using primary key displayed in form (I mean the [Forms]![Form Name].[Field] ) as the where clause.
But the results returns blank. I'm Stuck here. I'm not sure if the query is not working due to the Input Mask or because of something else. Please help me. Thanks in advance
You should add to form field listbox, and set following values:
Data: primary key of your first table
After this, that field will duplicate ID value. Now you should transform RecordSource of this field in order to see contents from second table. So you should set:
SELECT [PrimaryForeignKeyID], [DetailedField] FROM tblSecond;. Actually I don't know the contents of your second table. Whereas PrimaryForeignKeyID is a field that links second table to first, so-called FK.
After this set following properties of list box:
ColumnCount = 2
ColumnWidth = 0;2
AllowEdits = False
Save form and open it for viewing.
In this case, your listbox will show the associated contents of second table on form.
So to my mind it is better for you to do such simple tables and forms, and you'll realize idea.
I have a table with a combination of Text Boxes and Comboboxes all bound to fields in a Users table.
The combo boxes are used to select items such as Location, Access rights and Title which are all listed in seperate tables.
However as the values for Location, Access rights and Title are stored in my users table as the integer Primary keys from the related tables this is what is being displayed on my form.
How do I set the combobox field to display the Loc_Name rather than the Loc_ID but still be bound to the original users table?
The second problem I have is that when I select the dropdown for the combo box I get the List of Locations (for example) which is fine and when I select the valid location it displays the Loc_Name in the combobox field. The problem here is that because the combobox is bound to an integer type field in the Users table the form will not accept the String Loc_Name only an integer value.
Am I going about this the wrong way????
Details of settings:
The Location combobox on my form is bound to the Location field in my users table which stores the foreign key integer value from the locations table.
The ComboBox datasource is set to the Locations Table Binding SOurce
The Combobox Display member is set to Loc_Name
The Combobox Value Member is set to Loc_ID
The Selected value is set to (None)
Sorry. Should have put this here.
Looks like I might have been going about it the wrong way. Instead of referencing the valueID with the combo box I had to create a SELECT that join the two data tables and display the Joined data. On update the combobox had to be set to reference the original ID Field. Seeming like a very roundabout way of doing it. No where near as neat as Access.
I am attempting to set the value of a combo box from a "Splash Screen" type form in Access that will take the user's computer name and load two combo boxes on another form with the Employee ID and Manager ID, which are both bound columns of the combo boxes, which are unbound themselves. I can get the IDs in the combo box, but i want it to still display column 2 (Names) of both combo boxes. Right now it just displays the IDs. Anyone got any ideas how i can get it to react like i actually picked it in the combo box?
So, comboboxes can sometimes be tricky, but once you get it down you should be good to go.
So, when looking at a Combobox's properties,
The Format tab :
ColumnCount: 2 <-- You want the ID and the Name
ColumnWidths: 0";1" <--- You're hiding the ID field, which is the first column
The data tab:
This is where you're going to tell Access what data you're supplying for your combobox.
Usually it's a query or table data source. If it's a query you should be selecting the ID and Name fields, and use that query in the RowSource property in the Data tab.
Row Source: Select ID, Name FROM YourTable
Row Source Type: Table/Query
When you use the Wizard to create the combobox, it's fairly straightforward. When Access asks you to format your data source, you completely shrink the ID column, so it hides it (but it's still there).
The steps would be:
I want the combobox to look up the values in a table or query
Select the Table or Query
Select the Fields (ID and Name seem appropriate for your scenario)
Any sorting you may want
The next screen is where we want to hide our ID column, so shrink it entirely
The next screen is where we tell Access that we want the ID to be in scope (selected) when we select a combobox item
Name it & be proud
Note: I'm working with a large complex database, so for clarity's sake I have simplified the set up below.
I struggled a bit with how to title the question since it's a bit of a complex question. I hope it's accurate enough....
A bit of background first:
I have an Access 2010 database that contains a one-to-many relationship between a table Called "Products" and a table called "Datasets" (ie I have a bunch of products, and each product has multiple datasets). Each has an autonumber key field (p_ID and d_ID respectively) as well as numerous other fields.
I have a form (lets call it frm_Main) that has two subforms: sub_Products (based on the "Products" table) and sub_Datasets (based on the "Datasets" table). On the main form I have a control ctrl_SelectedProduct which is linked to [sub_Products]![p_ID] to see which record in sub_Products is selected / has the focus, and the sub_Datasets subform is linked to this control so that it only displays Datasets records that belong to the selected Products record.
On the main form I also have a number of controls that I'm using for filtering the data in the subforms. For example, I have a control ctrl_Category. I have this control coded so that when the user changes the value of the control, a filter is applied that limits the records in sub_Products to only those that have a p_Category value equal to whatever is chosen in ctrl_Category. If the control is blank, it will show all records. All this works great when if comes to filtering based on fields in the Products table.
Now the problem:
My problem is that I also want to be able to filter based on fields in the Datasets table. For example, Datasets has a field called d_Status. I want the user to be able to chose the status in a control (ctrl_Status), and based on this:
1) sub_Products will be filtered to display only those Products records that have an assotiated Datasets record (or records) that has d_Status equal to whatever was chosen in ctrl_Status
then
2) when a Products record is selected in this filtered sub_Products, sub_Datasets will only show the Datasets records that has d_Status equal to whatever was chosen in ctrl_Status
I know how to do part2. But I have no idea how to get part1 to work. Since sub_Products is currently based on the Products table, which does not have the d_Status field, I have no way to filter it based on that field. Thus, I'm assuming my first step will be to change my setup so that sub_Products is based on a query that combines the two tables (or at least adds the d_Status field).
If I do that, however, I get duplicate Product records. I can't use the query's Unique Values property because if I have a product that has two datasets, one with status "Current" and a one with status "Archived", then those aren't considered duplicates, and the product info is there twice. If I don't have the status field displayed, it shows only unique products initially, but then I can't subsequently apply a filter based on that non-displayed field.
I also tried basing sub_Products on a Totals query in order to utilize the Group By functionality, but I still couldn't get it to work right. Even if I could I don't think that's the best solution, because you can only have 10 fields with Group By, and my Products table has more than 10 fields that I need displayed in sub_Products.
I feel like I'm now just going around in circles and am at a loss of what to try from here. Please help!
Couldn't you add something like this?
Private Sub ctrl_Category_AfterUpdate()
Form_frm_Main.Recordsource = "Select * from Products where p_ID IN(" & _
"Select p_ID from Datasets where d_Status = " & _
Me!ctrl_Category.Value & ")"
End Sub
Alternately, you can access the childform via the parent of the other child form.
This is a non-working snippet just to give you the idea:
Me.Parent.otherChildFormName.Form.Recordsource = whatever
I have an application in Access 2003 that I am working on. In it, I have an employee table, which is connected to two other tables. The two connected tables are tables that hold a few fixed KeyWords. In my main employee table, I just have the ID from the other table, rather than having the whole word.
I wanted to make a form for entering data into these tables, so I made a query from the three tables that shows the all the regular fields of the employee table except instead of those two ID's, I showed the words themselves.
I then made the form and set the query as the RecordSource. The fields that have keywords are Combo boxes on my form, and their ControlSource is the keyword field from the query (like I mentioned earlier, the value can only be one keyword out of a list). Now, the problem I face is this: When I want to see a single record, it shows the correct value in the ComboBox, but when dropdown the menu, it doesnt show any of the other values.
What is the best way to do this? Am I doing this in the wrong way?
Thank you
I'd approach this slightly differently, set the combo box Row Sources to include both the id and text fields (you can hide the ID column if required by setting it's width to zero). Now add the ID fields to the employee query; you shouldn't need to join the other tables to the Employee table in this query, these fields are foreign keys and the combo boxes should show the text for you automatically. Set the form Record Source to this query, now set the combo box Control Source to the appropriate ID value from the form Record Source.
If you let the wizard build a form for you based on the Employee table you will see this approach in action.
ControlSource is the column name of the table where any user entry will be saved.
RowSource is where you type the name of the saved query or manual query typed directly into that field, which is used to provide a list of available drop down options for the combo box.
RowSourceType should be set to Table/Query, which is based on aforementioned RowSource method.
Now to correct the problem of only displaying what you begin to type (i.e. "Allow AutoCorrect" in Property Sheet > Other) or already have saved for that record without other options appearing after clicking the drop down is the following:
In Design View, click the combobox in question.
Property Sheet > Format > Column Count = set the desired number of columns to display in drop down.
Property Sheet > Format > Column Widths = set the desired width of column in the drop down.
Property Sheet > Format > List Width = set the desired width of the drop down itself.
Property Sheet > Data > Bound Column = set to the column of query table (i.e. 1 for ID and 2 for list options, if you only have two entries)
Note: If your desired drop down options are column two and not column one (makes things easier btw) then do the following change from above:
Property Sheet > Format > Column Count = set the desired number of columns to two.
Property Sheet > Format > Column Widths = add two entries 0",1" which means the ID field is not visible (0") and the options field is one-inch.
The easiest way to sort this out in the beginning is to view the column header names to know what you are looking at in the meantime by doing the following:
Property Sheet > Format > Column Heads = set to yes. At least you will know what is showing and whether or not you are on the right track.
I had this same issue in access 2016 and the issue was with my datatype. The combo box didnt accept 'Longtext' so i just changed datatype to 'shorttext' instead and all the values appeared.
You have set the query as the recordsource for the form. A form only shows (and ties to) ONE record at a time.
Since you want the combo box to show all the values, you should set the RecordSource of the ComboBox to your query.