How do I get three columns to concatenate into one combo-box in Access 2010 - sql

I have a combo-box in an Access 2010 form that I want to show the concatenation of three fields in three separate columns as a result. Currently, I only get the first column to show upon selection even though all three show in the dropdown. The previous questions I have looked at seem to deal with platforms I'm not using.
In a qry, I have the following simple SQL statement that combines all three into a Desc column.
SELECT tblReLetArea.CWHContractNo, tblReLetArea.ReLetAreaLot, tblReLetArea.ReLetAreaName, tblReLetArea.[CWHContractNo] & ": " & [ReLetAreaLot] & " - " & [ReLetAreaName] AS [Desc]
FROM tblReLetArea;
I have attempted variations but nothing changes and I don't get any error messages.

You need to set two things:
The amount of columns in the combobox (combobox.ColumnCount) must be set to 4
The column widths of the combobox (combobox.ColumnWidths) must be set to 0;0;0 to hide the first 3 columns
Note that you could indeed remove the first 3 columns from your query altogether, or reorder the columns. That would influence the availability of the columns in VBA.

Related

Referencing SQL fields from a DataSet where 2 field names are the same

I have the following SQL query which I am loading in to a DataSet:
SELECT i1.* , i2.* From tblMMLettersImportTable i1 Join tblMMLettersImportTable i2 on i1.SectionID + 1 = i2.SectionID Where i2.startpage - i1.endpage <> 1
Idea is to check that the index for various sections of a document lead one page on to the other with no gaps. I.e section 2 ends on page 5 and section 3 starts on page 6.
I'm happy that the SQL works, however by joining on itself the field "SectionID" is duplicated. In SQL easy enough, just use i1. or i2. to reference the correct one.
The issue comes when I load this in to a VB.net Dataset. I need to raise an error message with something like:
MessageBox.Show("There is a page gap between sections " & row.item("i1.sectionID") & " and " & row.item("i2.sectionID")
I get the error message Column 'i1.intline' does not belong to table Table. Makes sense as that is not its name in the dataset. I've considered using the column number to reference the item to pull out, however the SQL Table tblMMLettersImportTable is deleted, created and populated dynamically depending on the type of Letter/document being produced so I cannot always guarantee that the columns will always numbered the same. This is also why i1.* and i2.* is used instead of listing each column.
Is there a way that I can reference 2 items in a DataSet that have the same item name with VB.Net?

Queries in access runtime return different result

I have a form with a few controls. The values entered into the controls are passed to the WHERE clause of a query I use to populate a list box on the same form.
Some of the columns that I am filtering on have null values. When the control is left empty, it should pull in all rows unfiltered by that column.
So part of my WHERE clause looks like this:
WHERE
(person.last_name like [Forms]![frmFilterPerson]![txtLastName] & "*"
OR [Forms]![frmFilterPerson]![txtLastName] Is Null)
When I run my application in the full version of access, and I leave the txtLastName control blank, I get back ALL results, including the ones where the last name is null
However, when I run it in Access Runtime, I do not get all results, only the ones that have a value in the table for last name.
Any suggestions on how I can retrieve the rows that have null values while I have a filter in my where clause based on a control on my form?
You can use this old trick - comparing the field with itself:
WHERE
person.last_name Like Nz([Forms]![frmFilterPerson]![txtLastName], person.last_name) & "*"
OR
person.last_name Is Null
Or:
WHERE
person.last_name Like Nz([Forms]![frmFilterPerson]![txtLastName], person.last_name) & "*"
OR
[Forms]![frmFilterPerson]![txtLastName] Is Null

MS Access: divide result set into multiple pieces by text value or number of rows

I have a query against an Item table. This is all the items our library has, e.g., books, DVDs,CDs, etc.
I have to send a tab-delimited file that contains data on all these items.
There are over 100,000 items.
I'm stuck using MS Access.
Access can pull all the data, but it cannot send the result set via email because it is too big (over 65,535 rows; I am aware that later versions of Excel past 2007 can hold more rows but that does not help me).
All the columns are text data. So normal relational operators won't work (I tried).
I need to split the result set into two or three result sets in order to get it from Access to Excel. The need for Excel is that this is how the vendor expects it, and it needs to be tweaked some before shipping.
How can I divide it?
I have thought of at least two ways
If I can count rows, I can tell Access to use the first 60,0000 rows it gets. How do I tell it do that and then fetch only the second set of all the rows past 60,000. I have not figured out how to do this.
Divide based upon a field. The only field that is unique is the barcode, e.g., "30001001672906" Usually, the barcode is 14 numbers in length. I have experimented with using StrComp in a where clause, but I have a problem:
The barcodes are not in sorted order before they are fetched. "Order by" works on the result set, not how the data is processed before it is selected.
I am at a loss as to how to accomplish my big goal. That's the one that matters, not the particular way to fix my SQL to get it. I've looked at some pages, such as those below but not found a solution.
https://support.office.com/en-us/article/Table-of-operators-e1bc04d5-8b76-429f-a252-e9223117d6bd#__toc272228349
MS ACCESS count/sum number of rows, with no duplicates
http://www.techonthenet.com/access/functions/string/strcomp.php
I don't understand the problem with 2.
SELECT barcode FROM items ORDER BY barcode
Open a Recordset on that, move to record 60000, get the barcode
rst.Move 60000
strBarcode = rst!barcode
See https://msdn.microsoft.com/en-us/library/bb243789%28v=office.12%29.aspx
Then build your queries dynamically.
myQuerydef.SQL = "SELECT * FROM items WHERE barcode <= '" & strBarcode & "'"
Export the query e.g. with DoCmd.TransferSpreadsheet
myQuerydef.SQL = "SELECT * FROM items WHERE barcode > '" & strBarcode & "'"
Export to second file.
If you need more than two files, use an array instead of strBarcode and do
myQuerydef.SQL = "SELECT * FROM items WHERE barcode > '" & Barcode(i) & _
"' AND barcode <= '" & Barcode(i+1) & "'"

Edit first item of dynamic rows in ssrs?

My ssrs has three row groups nested, and in one of the rows the report runs many times.
I'd like to add something simple to the rows, such as "%" at the end, but only on the first row returned, not the rest of the dynamic rows. My idea was to use:
=RowNumber("detailsGroup") but all that returns is one for each row. Is there another SSRS method?
I was also thinking of using the "is" operator and comparing the dynamic values to the First operator, but running the report gave #ERROR.
If you are using groups you should be able to use Previous() function.
EXample:
Group 1 - ClientName
Group 2 - Region
Group 3 - SubRegion
Detail - data for above 3 groups
If I just want to add something in one of the detail data then I would use ..
=Fields!CallReason.Value + IIF(Previous(Fields!ClientName.Value) <> Fields!ClientName.Value , " Add Text For First Line", "")

Making Excel report into SSRS with Pivot Tables

I am trying to create a SSRS report from an ad hoc script I have. I can get results but the user of the report requests certain pivots that I can not seem to correctly display the information.
Below is an export of the report from sql with the pivots added. I want each row to be grouped by the GRADE first, OD second, and ID third. The pivot is adjusted for the STOCK NUMBERs. Each row with matching grade,OD, and ID will have numerous stock numbers.
http://i.imgur.com/Bx3yMuX.png
This is the closest I have have came to displaying the information in SSRS.
http://i.imgur.com/hpajKmB.png
Is there anyway I can have the Stock numbers run across a single row instead of a row for each stock number?
I would create a Column Group based on Stock number. That will generate a column for each Stock number.
It was a little more tricky than I thought. Since I did not want the Stock Number to actually be a column header but to just list on each column corresponding to my group it was not an actual pivot and was why it was not working properly.
Basically to get it to work I had to use the LookUpSet+Join function in SSRS to list the stock numbers out. I was not required to list them out on different columns. Thank-you for your replies.
Here is the code I used in the column
=Join(LookupSet(Fields!grade.Value & Fields!od.Value & Fields!wall.Value & Fields!id.Value, Fields!grade.Value & Fields!od.Value & Fields!wall.Value & Fields!id.Value, RTrim(Fields!stock_number.Value), "FOC"), ", ")