Help with Query design in MS-Access - sql

CredTypeID is a number the CredType is the type of Credential
I need the query to display the Credential in a drop down list so I can change the credential by selecting a new one.
Currently I have to know the CredTypeID number to change the Credential.
I just want to select it from a drop down list.
Currently to change Betty Smith to an RN I have to type “3” in the CredTypeID. I just want to be able to select “RN” from a drop down list.
Here is the table layout and sql view (from access)
SELECT Lawson_Employees.LawsonID, Lawson_Employees.LastName,
Lawson_Employees.FirstName, Lawson_DeptInfo.DisplayName,
Lawson_Employees.CredTypeID, tblCredTypes.CredType
FROM (Lawson_Employees
INNER JOIN Lawson_DeptInfo
ON Lawson_Employees.AccCode = Lawson_DeptInfo.AccCode)
INNER JOIN tblCredTypes
ON Lawson_Employees.CredTypeID = tblCredTypes.CredTypeID;

This should do the trick, will work in datasheet view and auto-set up the field as the type of dropdown you want if you add the field to any new forms.
Open the Lawson_Employees table in
design view.
Click on the CredType field and at
the bottom of the screen switch to
the "lookup" tab
Change DisplayControl to "Combobox
Change the Rowsource to be the
following query:
SELECT CREDTYPEID,CREDTYPE FROM tblCredTypes ORDER BY CREDTYPE ASC
Set columncount=2
Set Columnwidths to "0;"
Set LimitToList = Yes
Make sure BoundColumn is set to 1
If you have already added the Lawson_Employees.CredTypeID field to a form, delete it and then re-add it to get it to automatically set it up so you can select by the friendly label instead of the id.

If you are entering the data via a form, then you create a drop down list that uses two columns for it's value list (CredTypeID and CredType) and then set the width of the first column to zero. Hey presto, a field that access treats as having a value of CredTypeID, but displays with CredType.
I don't think you can use this trick directly in the query results themselves, though.

Related

Adding a condition to desplay a list of values in Oracle Apex

I need help with putting a condition on a List Of Values in Oracle apex. So I have 2 tables:
SELECT v.ID_VEZ NUMBER
v.BROJ_VEZ, NUMBER
v.MAX_DULJINA FLOAT
FROM VEZ v
and
SELECT b.ID_BRODICE NUMBER
b.REGISTRACIJA_BRODICE VARCHAR2(50)
b.DULJINA_BRODICE FLOAT
b.VEZ_FK NUMBER
FROM BRODICE b
The list of values displays v.BROJ_VEZ but returns v.ID_VEZ. The LOV is displayed in the form for the table BRODICE. I want the LOV to display only the v.BROJ_VEZ (returning v.ID_VEZ) where v.MAX_DULJINA > b.DULJINA_BRODICE. How do I do that ?. Is that even possible as a where clause in the LOV editor or do I need to make a dynamic action for it as the condition must be met only after my user wrote something in the form filed for b.DULJINA_BRODICE.
I'm 99% sure no one will understand what I want but I tried.
Presume this is page P1. Duljina brodice is then entered into P1_DULJINA_BRODICE item. Vez LoV would then reference page item as
select v.broj_vez as display_value,
v.id_vez as return_value
from vez v
where v.max_duljina > :P1_DULJINA_BRODICE
In order for it to properly work, scroll a little bit down (below the LoV query) and you'll see the Cascading list of values set of properties. Put P1_DULJINA_BRODICE into Parent Item(s) property.
(If query referenced some more page items, you'd name them all in "Parent Item(s)", comma-separated).
That should do it; you don't need dynamic action.
Sretan put i mirno more!

MS Access query with parameter from combobox in form does not return any results

I have created an MS Access database with several tables and queries but the problem described further down is about the following:
tEmployee table contains employee data as the name implies.
tCases table contains data about court cases.
Each case can be assigned to only one employee. I have created a relationship from [tCases]![assignedTo] field to tEmployee.
fSearches is a form to perform searches among the cases. It includes a combobox cEmployee which is populated from [tEmployee].[surname] and a command button to perform the search.
GOAL: to select employee in [fSearches]![cEmployee], hit the button and show all the cases assigned to this employee in another form named fResultsCases.
This is the code for the button where lines in comments are some of the things I've tried:
If cEmploee.ListIndex = -1 Then
MsgBox "You have to select employee to perform search.", title:="Missing value!"
Else
tHidden2.SetFocus
tHidden2.Text = "assigned to " & cEmploee & "."
DoCmd.OpenForm "fResultsCases"
'Forms("fResultsCases").RecordSource = "SELECT * FROM tCases WHERE [tCases]![assignedTo] like [Forms]![fSearches]![cEmploee];"
'Forms("fResultsCases").RecordSource = "SELECT * FROM tCases WHERE tCases .[assignedTo] = [Forms]![fSearches]![cEmploee];"
Forms("fResultsCases").RecordSource = "SELECT * FROM tCases WHERE [assignedTo] = [Forms]![fSearches]![cEmploee];"
Forms("fResultsCases").Recalc
End If
With all the above mentioned I get the following:
[fResultsCases] opens but does not return any case.
I tried to omit the WHERE clause and [fResultsCases] returns all cases as expected.
Then I tried to narrow things down to understand the problem by creating a simple query with one parameter and got exactly the same results.
SELECT tCases.[case number], tCases.subject, tCases.fromDt, tCases.toDt,
tCases.assignedTo, tCases.[date assigned], tCases.[date completed]
FROM tCases
WHERE (((tCases.assignedTo)=[Forms]![fSearches]![cEmploee]));
It seems like I'm missing something about the WHERE clause when it comes to combobox values but I can't figure it out. I am new to MS Access. Any help will be very appreciated.
UPDATE:
cEmploee rowsource property: SELECT [tEmployee].surname FROM tEmployee ORDER BY [surname];
cEmploee bound column property: 1
I cannot recreate your issue replicating your setup with combox that triggers an update of form's recordsource. And because neither an error is raised nor parameter input prompt appears, likely the WHERE clause is returning False (i.e., no matching records) and hence no rows are returned.
The reason can likely be due to the combobox [Forms]![fSearches]![cEmploee] which show Employee's surname but is bound to the unique ID as the default setup of Access' comboboxes (if using wizard). See Data tab of combobox's properties in Design View.
The reason for this hidden bound field is users never know the unique ID of a record but do know the value (i.e., name). So when they select the recognized name they are really selecting the corresponding unique ID. Therefore, consider adjusting WHERE condition accordingly where ID is the unique table ID field which matches the bound field of combobox.
Forms("fResultsCases").RecordSource = "SELECT * FROM tCases WHERE [ID] = [Forms]![fSearches]![cEmploee];"
Forms("fResultsCases").Recalc
Forms("fResultsCases").Form.Requery ' USUALLY THE RECORDSOURCE UPDATE CALL
After about ten days of "struggle" with this brainteaser, I decided to post this question to ask for help. Fortunatelly #Parfait has involved with my problem and with his/her accurate remarks helped me understand my mistakes. It also helped me Ken Sheridan's post here. So I am posting my answer just for future reference. #Parfait, I sincerely thank you for your time.
So the problem in this case was primarily understanding how relationships between tables affect data types. If you want to connect a textfield of tableA to tableB, then there are two cases. If the primary key in tableB is number then textfield becomes number. If the primary key in tableB is text then textfield remains text.
In my case it was the first one. Specifically the field [tCases]![assignedTo] after creating relationship with table [tEmployee], was turned automatically into number (It still shows the surname but contains the corresponding primary key in tEmployee). On the contrary combobox [cEmploee] still contained text. This why this line:
Forms("fResultsCases").RecordSource = "SELECT * FROM tCases WHERE [assignedTo] = [Forms]![fSearches]![cEmploee];"
was not returning any record as #Parfait successfully guessed.
At this point there were two possible solutions:
1) Set surname as primary key to agree with combobox contents.
delete the relationship between [tCases]![assignedTo] and [tEmployee].
set field [tEmployee]![surname] (which is text) as primary key in table [tEmployee].
create a new relationship between [tCases]![assignedTo] and [tEmployee].
I did not try this solution though, as a problem would occur if 2 employees had the same surname. So I suggest following the second.
2) Keep the same primary key and use it to match the records from tableA to the surname from tableB.
To achieve this you have to inform access, that you want the records from tableA that have the ID, while in tableB this ID corresponds to the surname inserted in the combobox (hope this makes sense). In other words create a recordset of both tables (union query). For this purpose I replaced the above refered line of code with the following:
Forms("fResultsCases").RecordSource = "SELECT tCases.* FROM tCases INNER JOIN tEmployee ON tCases.[assignedTo] = tEmployee.[employeeID] " & _
"WHERE tEmployee.[surname]=[Forms]![fSearches]![cEmploee] AND tCases![assignedTo]=[tEmployee]![employeeID];"
Hope this saves some time from other people. Have a nice day!

Using Lookup in MS Access Forms

I have a MS Access Form that has Student ID,
This is ok, I can see student ID as it should be
What I want is to display Student Name instead of Student ID
I used SELECT StID, StName From Students in "Row Source"
"Row Source Type" = Table/Query
"Bound Column" = 1
I could not find any property where I can decide the Display Column
Help is much appreciated.
Thanks
Go to the "FORMAT" tab of the Form Properties Dialog Window (the same one you used to set the Row Source and Row Source Type properties)
You'll see two fields (Column Count and Column Widths)
Set Column Count to 2.
Set Column Widths to 0";1"
This works in Access 2007. Any version later then 2007 should also work.
By setting the column count to '2' you're displaying the StudentId and the Name. Then by setting StudentId column width to '0' you are hiding the column.
When you switch to Form View you will see the Student Names, but the value stored underneath is really the StudentId. Neat trick.
Hope this helps.

Excel query using Transfer Data from System i

I am looking for information on how I can use the Transfer Data from System i Add-In for Excel to only get data that equals the data in one of my columns (both sets of data are strings). Unfortunately, I cannot just get the entire contents of the System i table since it contains more than the maximum allowed in Excel. Thank you!
Additional information for clarification purposes:
I'm trying to get specific data from the iSeries table. If the field in the iSeries = column A, I want that data placed in column c.
COLUMN A COLUMN B COLUMN C
100 xxxxx
on the iSeries table
FIELD 1 = 40 FIELD 2 = ITEMDESC1
FIELD 1 = 100 FIELD 2 = ITEMDESC2
FIELD 1 = 500 FIELD 2 = ITEMDESC3
In this case it would place ITEMDESC2 into column C since FIELD 1 = 100
I just need to know if there is a way within the WHERE clause using the Data Transfer for System i to do this?
I hope this is clearer
Data Transfer is a simple file transfer. It isn't intended to make decisions on how to select DB2 data based on the contents of various cells in an existing spreadsheet. As a workaround, you can upload the existing spreadsheet to DB2 and then use IBM i Navigator's SQL Script function, join the uploaded Excel table to your DB2 table and use CASE to put the proper field into the proper column.
select columna, columnb, case when field1 = columna then field2 else ' ' end
from excelupload join db2table on some_join_criteria
where some_record_selection_criteria
It seems easier to transfer the file to the PC and do the column manipulation in Excel.
Alternate Approach:
You could write whatever query you like in an iNavigator RunSqlStm window. Set the option to save results, before you run the query. Once you run the query, you can save results in several formats, including Excel. If there are too many rows for your version of Excel, then you can save it as a .CSV file.
Create a new request
Fill in system name (Next)
Fill in table name (Next)
Click "Data Options..."
On this panel is a SELECT and a WHERE clause. Put the cursor in the Where box, click "Details..." and create your query. Click "Apply" and then "OK".

MS Access Query-By-Form Issue

I have a form (fCen1-20) containing two combo boxes. The first combo box is called Lookup Value and the dropdown contains the field Lookup_Value which serves as the primary key for every table in the database. The second combo box is called Category and the dropdown contains the fields Category, Code, and Table.
I would like for the user to select the Lookup Value and Category and for those selections to inform a query which returns the value of the selected Category for the selected Lookup Value. The complicating factor is that each Lookup Value is associated with over 1500 unique categories of information which are each assigned a unique code -- the code serves as the field name.
For your reference, I have pasted my code, along with my rationale, below:
SELECT [Forms]![fCen1-20]![Category 1].Code
' Rationale: Get the value for the Code associated with a given category
FROM [Forms]![fCen1-20]![Category 1].Table
' Rationale: Reference the Table where the selected Category/Code is housed
ON [Forms]![fCen1-20]![Category 1].Table.Lookup_Value = _
[Forms]![fCen1-20].[Lookup Value];
' Rationale: Select only those records in the table
' for which the Lookup_Value field matches the Lookup Value
' selected in the form
When I run this code, I'm given a "Syntax error in FROM clause" error. Any suggestions on how to make this work? Please let me know if you'd like any additional detail or clarification. Thanks!
If you use this in a query, it will probably work assuming the form fCen1-20 is open in Form View.
SELECT [Forms]![fCen1-20]![Category 1]
The value returned will be from the bound column of the currently selected combo box row. The fact that [Category 1] includes 3 columns does not matter. The db engine only sees the column which is "bound". (Check the combo's Bound Column property on the Data tab of the combo's property sheet.) The bound value is the only combo value available in a query.
You can not append a column name to the combo name to retrieve the values from those columns, so these will both fail:
[Forms]![fCen1-20]![Category 1].Code
[Forms]![fCen1-20]![Category 1].Table
That was my explanation for why I believe your approach is not working. However, I don't know what to suggest instead. In general, if you use a table's primary key as a combo's bound value, you can use that bound value with a DLookup expression in a query. As an example, assuming all values are numeric ...
SELECT fld1, fld2, etc
FROM YourTable
WHERE some_field = DLookup(
"lookup_field",
"AnotherTable",
"pkey_field = " & [Forms]![fCen1-20]![Category 1]
);
Unfortunately I don't know whether that suggestion is useful for your situation because I don't clearly understand what you're trying to accomplish.