How to make a drop down list (list box)in an MS Acess Query with values from two different tables - sql

I need the drop down box above to display the date as shown and the ClassTypeDesc as you can see above the dropdown list shows 1/12/2010 twice. They have different ClassTypes Assigned to them.
The drop down list should show:
1/12/2010 ACLS-I Day One AM
1/12/2010 ACLS-I Day One PM
I need to know the statement to put in the Row Source Box on the lookup tab in the Field Properties to make this work.
Related Question on Making a drop down list

There's no need to concatenate the two columns. Based on the diagram, the SQL for your lookup combo box should look like this:
SELECT tblClassSession.SessionID, tblClassSession.Date, tblSessionType.ClassTypeDesc
FROM tblClassSession INNER JOIN tblSessionType
ON tblClassSession.SessionTypeID = tblSessionType.SessionTypeID;
Then in the properties for your lookup combo box, change ColumnCount to 3, and Column Widths to 0 (if you want to size the other columns, change Column Width sto something like 0";.75";1.5", and the List Width property to 2.25").
I may have gotten some of the field names wrong, but that's the basic idea.
(also, you probably really ought to rename tblClassSession.Date to tblClassSession.SessionDate so you don't run into problems with the fact that Date is a reserved word)

As you already have the right number of rows, you just need to concatenate enough fields to make it more useful, so your query would be something like:
SELECT c.Date + ' ' + s.ClassTypeDesc AS YourFieldName
FROM...

Related

Concatenation and proportion in access

A little background:
I have two tables imported from excel. One is 300k + rows so when I do updates to it in excel it just runs too slow, and often doesn't process on my comp. Anyways, I used a 'outer' left join to bring the two together.
Now when I run the query, I get the result which works fine but I need to add some fields to these results.
I am hoping to mimic what Ive done in excel, so I can create my summary pivots in the same manner.
First, I need a field that just concatenates two others after the join.
Then I need to add a field the equivalent of:
1/Countif($T$2:$T$3330,T2) from excel to access. However, the range does not need to be fixed. I will get it so that all the text entries are at the top of the field, so in theory, i need the equivalent of Sheets("").Range("T2").End(xldown). This proportion is used to eliminate double counting when i do pivot tables.
I am probably making this much more complicated than it has to be but I am new to Access as well, so please try to explain some things in explanations.
Thanks
Edit: I currently have:
Select [Table1].*, [Table2].PlaySk, [Table2].Service
From [Table1] Left Join [Table2] On [Table1].Play + [Table1].Skill
= [Table2].PlaySk
And in a general case, what I am trying to solve is something to get ColAB and ColProportion.
ColA ColB ColAB ColProportion
a 1 a1 .5
b 1 b1 1
a 1 a1 .5
b 2 b2 .3333333
b 2 b2 .3333333
b 2 b2 .3333333
Sounds to me like you'll need to make a couple queries in sequence to do everything you need.
The first part (concatenate) is relatively easy though -- just take the two field names you wish to concatenate together, say [Play] and [Skill], and, in design view, make a new field like "PlaySk: [Play] & [Skill]".
If you want to put a character between them (I often do when I concatenate, just to keep things straight), like a semicolon for example, you can do "PlaySk: [Play] & ';' & [Skill]".
As for the second part, I think you'll want to build a "Group By" query on top of the other one. In your original query, make another field in design view like this: "T2_Counter: Iif([The field you're checking, i.e. whatever column T is] = 'whatever value you're checking for, i.e. whatever T2 is',1,0)". This will result in a column that's a 1 when the check is true, and a zero otherwise.
Then bring this query into a new one, click "Totals" at the top in the Design tab, then bring the fields you want to group by down. Then create a field in design view like this: "MagicField: 1/Sum(T2_Counter)".
Hopefully this helps get you started at least.

How to assign one same label for multiple value in non-queried available values in ssrs 2005 report?

Parameters - Multiple Values For One Label - Possible?
Sorry my modified Question.....
I have question to ask,...
Is it possible to have multiple values for ONE label in non-queried available values in SSRS 2005? i want to join fields value in a single row like,
Works: (But this bring a long list in drop down menu - which i donot want)
Label Value
---------------------------
Site-1 150
Site-1 151
Site-2 152
Site-2 153
Required result (Which i want - in one line)
Label Value
---------------------------
Site-1 150,151
Site-2 152,153
(which will bring one label and related multi-value in drop down or combo box.
But the problem is that ColumnName IN (#Site) does not work with multi-value.)
More description of the problem:
Let say, I have a field/column
Name = Site
Value = C150,C151, C152, C153
I want drop down menu on report with
C150,C151(as Site-1) & C152,C153(as Site-2)
So I created parameter i.e. #getSite and set values as
multi-value in the report as
Label Value
---------------------------------------------
Site-1 (150,151)
Site-2 (152,153)
And set my parameter as #getSite:= Parameters!#getSite.Value
And Query i wrote as,
SELECT * FROM ..
WHERE Site IN (#getDisease)
But after all these, my report result is empty,literally no result.
It seems like if i select only one value as Site-1 = 150, then it works
but not two or more values in one line,
why it is not possible?? if yes then how?
Please help!!!
Yes just Right Click on your parameter in your Report Data window under Parameters folder and select the check box for allow multiple values as follows
this is what I said before you need to put your column name inside a set of paranthesis something like this
SELECT * FROM ..
WHERE (Site IN (#getDisease))
I have been working on this problem for a while and I think I have finally figured it out...
Basically you need to use a backwards case statement in your SELECT statement, put that in a derived query and then reference it in the outer WHERE clause..
SQL:
SELECT * FROM
(
SELECT
Label
, value
, CASE WHEN [value] IN (150,151) THEN 'site-1' WHEN [value] IN (152,153) THEN 'site-2' END AS [grouped_values]
)
WHERE grouped_values IN (#getSite);
*Note: This answer only works on values that are mutually exclusive, if both sets had the same value included then it would be problematic..
--
Hopefully this can put you in the right direction. I am finding a lot of the reporting services tricks require reverse engineering or at least some reverse thinking.
cheers,
Michael

vb if condition on items and price from database

I actually have a Access database where i have a table called "tblfreight" and two column is there (items and Price)
And I want to auto show the Price when I choose Items.
There is two Textbox: "txtitems" and "txtprice"
I want to be like this....
If txtitems.text = select from tblfreight and column items Then
txtprice.text = select from tblfreight and column Price
Else txtprice.text=0 (Zero)
You need to query your DB first..
Select * from tblfreight - will get you your data you need.
Then you need to put this data somewhere. You can use a combobox for this. Once you have your combobox filled with your data you then can set the price into a label or textbox easily.
You can use the combobox selected index changed event...
Inside the changed event something like this would work...
textprice.text = Combobox.selecteditem.value
This will give you a great start, that's why this answer just gives you the steps and not the full code.

Display text corresponding to Combobox selection in Microsoft Access 2010

I have a contact form and one of the fields in a the form is a Contact_Type_ID. This field is a number field which also corresponds to a text field in another table (e.g. 1 = expatriate).
When I cycle through the contacts, their Contact_Type_ID is 1, 2, 3... instead of Non-profit, CEO, Vice-president, etc. This is a problem because one has no idea what number 3 means.
I would like to a combobox that only displays the corresponding text.
I can't get the two columns and 0;1 format to work. My hunch is that it's because I'm drawing information from two different tables. I can generate the correct list, but then the main entry doesn't change as I cycle through the contacts to reflect the current contact's [Contact_Type_ID].
I can't edit any of the current tables because I am supposed to apply this application to a much larger scale database.
I also tried setting the SQL for the row source:
'Populate the connection combo box '
Dim typeSQL As String
typeSQL = "SELECT DISTINCT Contacts.[ContactTypeID], Contact_Types.[ContactType] " & _
"FROM Contacts, Contact_Types " & _
"ORDER BY Contact_Types.[ContactType];"
Me.cbo_ContactType.RowSource = typeSQL
However, I then have the same problem: the combobox won't update as I cycle through the contacts. I don't understand the difference between the rowsource and the controlsource. I feel that this distinction might be key here.
Assuming I understand correctly:
In the combo box properties, go to the Data tab.
Set the Control Source to Contact_Type_ID.
This means that when you go through the records, the combo box will correspond to the Contact_Type_ID field from your data.
Set the Row Source to "SELECT Contacts.[ContactTypeID], Contact_Types.[ContactType] FROM Contacts, Contact_Types ORDER BY Contact_Types.[ContactType];"
The Row Source indicates the data that the combo box has access to, which will help it determine how to display the control source value.
Set the Bound Column to 1
Set Limit to List to Yes
Now in the Format tab. Change Column Count to 2.
Next set the column widths to the 0;1 you mentioned in your question.
Now try looking at form view, and it should behave as you expected.
If it does not work, create a new control with these instructions.
As I understand your question, you have a form with contacts based on a table Contacts and that table contains a field called either Contact_Type_ID or ContactTypeID. You wish to display the description of the contact type from a table Contact_Types.
You do not need to join tables for your combo, it should be very simple. The key, as you suspected, is the Control source, which is the property that relates one table to another.
Control source : ContactTypeID '' or Contact_Type_ID, choose from the list
Row source : SELECT ContactTypeID, ContactType FROM Contact_Types ORDER BY ContactType
Bound column : 1
Column count : 2
Column widths : 0,2
As an aside, you can join tables in a combo and still set the first column to 0 and it will still work, it is all in the correct set up.

one problem in fetching a data from backend in vb.net

i have two item in form it is---1 is textbox and 2nd is combo box.
now i have single value in textbox .
but there is a multiple value for a combobox with is totally depend on a value of textbox....
*i am already add data to the backend files ... in which 1 columns that is called column A it's value is for textbox and 2 column that is called column B it's value for combo box *
When i write in textbox it's dependent ALL value can be get in the combo box.
Can any one solve my problem... It is a row vice search.....
I used a Ms Access for my backend......
How i can create a table that can be i used for a my problem
Give me any reference or codes.
This is probably Category->Product kind of scenario, where ONE Category can have ONE or MORE Products,
Category "Softdrink" can have Products("Coke","Pepsi" etc.)
Category "Harddrink" can have Products("8 PM","BP",etc.)
So when u will put "Softdrink" in your textbox then you want to get the relevant products for it. (Assumed you are using TextChange event)
SQL - select Product.Name from Category Inner Join Product On Category.Id= Product.Category_Id where CategoryName ="Softdrink"
and table structure would be like,