I have a library database. There are some kind of data (books, magazines and etc.).
I have a form on base of report of these data. In this example I'm trying to add in combobox just one value - Name of the book. I'm doing it by such a query in row source of the combobox:
SELECT [Forms]![books_list]![name] AS id;
books_list - the name of the form and name is the text box called name.
It returns only the first name of the book in all comboboxes - 123.
I need to show only these name values in different comboboxex, which has reference by the row.
To make it clearer - in first combobox - 123, second - Прошлое, third - May be next time.
As I understand, you want to take the value from the text box name, and use a query to select the same value in the combo box?
SELECT <insert your column name here>
FROM <insert your table name here>
GROUP BY <insert your column name here>
HAVING ((<insert column name here>)=[Forms]![books_list]![name] AS id);
Related
I have two tables:
'tableStudent' - a list of students given an ID number by the table, with following columns:
student_ID
last_name
first_name
and 'tableProject' which gives each project an ID and will be used to store information about the students involved in the project. Students will work in pairs on the project. This table includes the following columns:
project_ID
project_title
student1_ID
student2_ID
The columns student1_ID and student2_ID are combo-boxes that link student_ID to the student names.
I want to create a form that can be used to record students involved in a project. I want to be able to select the student IDs and have the student names autofill on a form.
I can make a form that autofills, but only with one student with this SQL:
SELECT tableProject.project_ID, tableProject.project_title, tableProject.student1_ID, tableStudent.last_name, tableStudent.first_name
FROM tableStudent INNER JOIN tableProject ON (tableStudent.student_ID = tableProject.student2_ID) AND (tableStudent.student_ID = tableProject.student1_ID);
When I add Student 2, I get a duplicate error on the student names. How do I indicate that the two names belong to different students? This is the code I'm generating:
SELECT tableProject.project_ID, tableProject.project_title, tableProject.student1_ID, tableStudent.last_name, tableStudent.first_name, tableProject.student2_ID, tableStudent.last_name, tableStudent.first_name
FROM tableStudent INNER JOIN tableProject ON (tableStudent.student_ID = tableProject.student2_ID) AND (tableStudent.student_ID = tableProject.student1_ID);
Any help appreciated!
Options for displaying related info from lookup table:
Use Access query designer to build form RecordSource. Pull tableStudent into query designer. In your case pull in twice - second instance will get named like tableStudent_1. Join each to one of the student fields. Bind textboxes to both sets of lookup table fields and set them as Locked Yes to prevent edit.
Don't include lookup table in form RecordSource at all. Include all student info in combobox RowSource. Expressions in textboxes refer to combobox columns by index, index begins with 0: =[comboboxName].Column(1)
DLookup() domain aggregate function, however, since your tables have a relationship, this is an inefficient method.
For all options, set textboxes with TabStop No.
I am trying to create a pie chart in a MS Access report. The problem is that the field in the table from which I am trying to draw the data is a lookup field, drawing its data from another table. So when the pie chart is rendered, the labels are coming up as the numerical id for the entries rather than the text labels.
The structure is something like this:
Discrepancies Table:
column1 - ID
column2 - Name
column3 - Category - lookup from categories table
Categories Table:
ID
category (name of the category)
In the discrepancies form I have the category field bound to the "category" column (column1), so the text label appears in the table.
However, in the pie chart, which draws from the category field in the Discrepancies table, the label is the numeric ID of the category rather than the name.
How can I get the name to appear as the label rather than the ID?
I figured it out by creating and basing my pie chart on a query, rather than by pointing it a row source.
The query was SELECT DISTINCTROW categories.category, Count(*) AS [Count Of discrepancies]
FROM categories INNER JOIN discrepancies ON categories.[ID] = discrepancies.[category]
GROUP BY categories.category;
Structure of DB is:
Org_Year(Table)
ID
Org_Name_ID
Org_Year
Ft(Table)
ID
Org_Year_ID
Count
Org_Name(Table)
ID
Org_Name
I've created a form to input data into Ft.
Form has reference to Org_name. I should be able to choose between different org first. Afterwards i want to choose which year to enter data into Ft for. I only want to be presented with a list of Years according to the entries in the Org_Year table, where org matches my selection in the dropdown above.
The query to populate the select box (Org_year_Box) is:
SELECT Org_Year
FROM Org_Year
WHERE Org_Name_ID=Organisation_Name_ID.value;
I't doesn't return the Years for the given Org_id when using the above query. But if i replace "Organisation_Name_ID.value" with the actual value ie. "2" it returns the correct years.
How to do?
You need to do something like this.. You are missing a Group By..
SELECT Org_Year
FROM Org_Year
WHERE Org_Name_ID=Organisation_Name_ID.value;
Group By Org_Year.Org_Year
I created a SSRS report with a dropdown to parameterize data being reported. This works fine. I now need to add another parameter to filter the report a little further. For example, I have a location dropdown that shows area, country, region, etc. I need to add another dropdown that is dependant on the first dropdown. So if I select "country" in the 1st dropdown, I show the list of countries in the 2nd dropdown or if I select Region - I show list of Regions in the 2nd dropdown. Country, Area, Region data is stored in different tables. So basically my query needs to be smart enough to run the appropriate sql based on 1st dropdown selection.
Thanks so much for any assistance given.
One of the powerful features of Reporting Services is that everything is an expression, including the dataset's SQL statement.
Let's say your first parameter (the one that describes what to select) is called Location and it selects a list of locations such as country, region, etc. Perhaps you get that from a table which has a LocationId and a Description like so:
SELECT LocationId, Description FROM Locations
You hook up the Location parameter to this query to get your drop down list of location selectors for the Location parameter.
Now create a second parameter called Select where we want to select from a list of countries or regions. To keep it simple, I'm going to assume there are only two locations: Country with a LocationId of 1 and Region with a LocationId of 2.
Create a new dataset called Selections and manually add fields to it called Id and Description. Hook up your Select parameter to this dataset. Now for the SQL Statement for the Selections dataset, enter the following expression:
=IIF(Parameters!Location.Value = 1,
"SELECT CountryId AS Id, CountryName AS Description FROM Countries",
"SELECT RegionId AS Id, RegionName AS Description FROM Regions")
So, where the Location parameter is set to 1 (Country) you select from the Countries table otherwise you select from the Regions table. You alias the field names so you get consistently named fields for your dataset for use in the Select parameter query. Obviously, you can extend this to more selections as required.
You get the idea but this is a little fragile - whenever you want to add a new location type you have to go through all your reports and update the SQL statement for the Selections dataset. That's tedious and no one wants that job. What we want is an automated system where all reports get the new selections whenever they are added.
So let's add a column to the Locations table, called SQLStatement. For the Country row, this will have the value:
SELECT CountryId AS Id, CountryName AS Description FROM Countries
For the Region row, the SQLStatement field has the value:
SELECT RegionId AS Id, RegionName AS Description FROM Regions
Now the Locations table has the value of the SQLStatement in it for the Selections dataset. You can't use this directly (your dataset would just return the value of the SQL statement field, not execute it) but you want to have something that returns this string as the expression to use for the SQL statement for the Selections dataset. Custom code can be used to do this. So the expression to use for the Selections dataset will be something like this:
=Code.GetSQLStatement(Parameters!Location.Value)
And then you have custom code function like this (significant parts left out):
Public Function GetSQLStatement(LocationId As Integer) As String
Dim SQL As String
SQL = "SELECT SQLStatement FROM Locations WHERE LocationId = " + CStr(LocationId)
' Connect to database, get SQLStatement field
GetSQLStatement = <Field Value>
End Function
When you want to add another location selection, for example continents, all you have to do is add another row to the Locations table, say LocationId = 3, Description = Continent and SQLStatement = SELECT ContinentId AS Id, ContinentName AS Description FROM Continents and now every report you have that selects by location will be able to use Continents.
First dataset add this SQL
Select ContryName, CountryID From Country
Assuming the name the above dataset's parameter is #country add the following SQL on the second dataset
Select RegionName, RegionID From Region
Where CountryID IN( #country)
It is very simple. Let’s assume that the data of the table “ONE” as follows:
**Location_Type** **Location**
Country India
Country Sri Lanka
Country China
Country Japan
City Bangalore
City Hyderabad
City Delhi
Ex:- Query for the Report parameter (#Location_Type1):
Select Distinct Location_Type from One
Query for the second Report Parameter:
Select Location from ONE where Location_Type = #Location_Type1.
Please let me know if it is not clear.
I have a combo box which has 3 pieces of information
COMBO BOX 210: Materials ID, Name of Product, Cost, Description
After I update the combo box the cost figure is stored in another field in the table, so far so good, so in selecting "Apples" the cost "$1" stores.
Now, what I want to is have a different field where the description of the apple (the text) is stored yet I only update the combo box once, in other words after updating the combo box Field 1 stores the price and Field 2 the description of the apple.
I will offer you a different example which I hope is similar to what you're asking.
My form includes a combo named cboNames. This is the query for its row source:
SELECT f.id, f.fname, f.date_added
FROM food_test AS f
ORDER BY f.fname, f.date_added;
In the combo's After Update event I can access the values of those 3 columns in the selected combo row by referring to the Column index. Notice the column index numbering starts with zero.
Private Sub cboNames_AfterUpdate()
Debug.Print Me.cboNames.Column(0)
Debug.Print Me.cboNames.Column(1)
Debug.Print Me.cboNames.Column(2)
End Sub
So if I wanted to put the date_added value into another data control, I could add this to the combo's After Update event.
Me.SomeOtherControl = Me.cboNames.Colummn(2)
However I wouldn't actually store both id and date_added in a row of another table. In my food table, each id is associated with a unique combination of fname and date_added. So I would store only the id, and use a SELECT with a JOIN to the food table to look up the associated fname and date_added values whenever I needed them.