Add Items of Multiple Orders into a Single Bill (Crystal Report) - vb.net

I'm working in visual studio with vb.net and crystal report where I have few tables that store the order information of any restaurant. I want to print the bill of any order for the guest and also in case if guest has placed the order multiple times in a restaurant.
I'm attaching a image that will give you some sort of details about the scenario where 3 tables are designed with bill format as a output.
I want to use a record selection formula for any particular table to print the items details in Bill for all the order placed. Table 2 & 3 are linked to each other with 'Order No'. When I give the command to print the bill for table 'T1' it should give me the details as shown in the bill format which include all the order items from table 'TableOrderedItems' for the list of order numbers placed for that particular table (i.e. T1).
Firstly, I create a list of all orders that pertain to table # 'T1' like ("K1", "K2"). Then I will look into table 'TableOrderedItems' for each order no. in list and get printed all the items in bill (see image).`
Dim cryRptBill As New ReportDocument
Dim RepLocationBill As String
RepLocationBill = Application.StartupPath & "\CryRptBillTable.rpt"
cryRptBill.Load(RepLocationBill)
cryRptBill.RecordSelectionFormula = "{TableOrderedItems.OrderNumber}=" & " in [" + kotList + "]"
Image For Tables & Bill Format

I think you want this:
CryRpt.RecordSelectionFotmula= "{tblUsers.ID} in [" + List + "]"
This assumes your list is a string with number and commas. For example "1, 3, 4"

Related

User-entered number of pages to print in MS Access VBA

Is it possible to have a user enter the desired number of pages they wish to print onto a form, and be able to print "Page X of Y" on each page?
I have a small shipping label application that requires a dynamic number of labels to be printed for any given shipment, and is entered by the user.
The data used for the label information is returned from the following stored procedure
SELECT C1.CompanyName,
C1.Address1,
C1.Address2,
C1.City,
C1.Province,
C1.PostalCode,
C2.CustomerName,
C2.ShippingAddress1,
C2.ShippingAddress2,
C2.ShippingAddress3,
C2.ShippingAddress4,
C2.City,
C2.Province,
C2.PostalCode
FROM MyCompany_tb C1,
Customer_tb C2
WHERE C2.CustomerID = #CUSTOMER_ID
AND C2.InvoiceNumber = #INVOICE_NUMBER
This will produce a single record that includes my company "return address" information (C1), and pairs it with the the customer's shipping information (C2). The label(s) that get
printed need to print out "Box 1 of 3", "Box 2 of 3", etc, depending on the value entered by the user.
I found this article, but I would prefer to do this without creating a "temp table" in Access. Is something like this possible?
You need an additional table, but it can be a simple number table, with one LongInt column ID with numbers 1..n
Then use a cartesian product to get the number of records you want.
In VBA:
' lngNumRecords is the number entered by the user
TempVars.Add "NumRecords", lngNumRecords
The query:
SELECT YourQuery.*, "Box " & [tblNumbers].[ID] & " of " & [TempVars]![NumRecords] AS BoxNo
FROM YourQuery, tblNumbers
WHERE tblNumbers.ID <= [TempVars]![NumRecords]
There is no JOIN, so you get your main record replicated as many times as IDs are specified.
This assumes that YourQuery returns exactly one record.

Updating filling in blanks on SQL table based on csv

I am working on a small project at my office to do some clean up on our customers table stored in SQL Server and a similar one stored in PostgreSQL. Basically we found many customers have one or several columns that have 0 or are blank and need to be filled in. Our plan is to first gather all of the data for the 0 or blank columns and fill in the csv, and then somehow script it to fill in the blank columns for each customer.
Below is an example of what the current table looks like with 0s and blank columns. It's random as to which column or columns need to be filled in for a given customer (the one thing we always have is the customer's username).
username emp_num title email phone
-------------------------------------------------------------------
jsmith 0 Manager jsmith#somewhere.com
kjones 112222 Clerk 111-222-3333
wgarcia 0 wgarcis#domain.com 444-555-6666
We would be filling in anything with "0" with a 6 digit number and any blanks would have values filled in on the csv.
Question is, after I have a completed csv with all customer info, how might I go about:
loading the csv into SQL; and
scripting this to compare the csv file against the existing customer table and fill in only what's missing? (i.e. 0s and blanks).
Can anyone share example SQL queries to get me started? (How might it need to be approached differently for PostgreSQL?)
TIA,
Chris
Update off a join to the correct customer table like this:
update a
set a.emp_num=b.emp_num
from currenttable a join customer b on a.username=b.username
where a.emp_num in (0,'')
Presumably this is a one time task. You can do this very easily with some simple string building using Excel or another spreadsheet application. It won't be reusable, but it's often the quickest solution.
That said it isn't going to work if you have a very large number of customers, but it'll do the trick for several thousand.
Excel Formula
="UPDATE YourTable SET emp_num = " & B2 & ", title = '" & C2 & "', email = '" & D2 & "', phone = '" & E2 & "' WHERE username = '" & A2 & "'"
Simply copy the formula to all the rows in your csv, and execute the generated queries.

INSERT data FROM sql query with one constant value in MS Access with SQL

I am trying to create a form for MS Access where you at first search for companies in a table based on criteria. The returned data is simply the names of the matching companies. I then want to take these names and add them to a different table.
So far there are 3 tables: one stores the User Names (tblStartup), one Stores the Company Names (tblVC) and one shall be used to save the matches (tblContact).
The problem I have is that I want to add a constant user name alongside the data from the query.
So e.g. "MAX" searches for companies that are from Automotive. He gets a list of matching companies e.g BMW, DAIMLER and AUDI.
So the data which should be added to the table tblContact would be:
MAX BMW
MAX DAIMLER
MAX AUDI
INSERT INTO...SELECT... doesn´t work because I not only need to add the Info from the query but also a constant which the User selects from a Combobox(e.g. the user selects "MAX" and then uses the button "query" to find matching companies for MAX, then the button "add to Contacts".
This is the code I have so far:
Dim sql As String
sql = "INSERT INTO tblContact(txtNameStart, txtNameVC) " & _
"SELECT txtName FROM tblVC WHERE Branche ='" & Me.cboBranchen & "';"
So how do I put my constant User Name inside the query). Would it be something like SELECT... AND VALUES...?
Regards
Max
You can just use an INSERT INTO .... SELECT .... statement, with one column and one constant value.
Example:
sql = "INSERT INTO tblContact(txtNameStart, txtNameVC) " & _
"SELECT """ & Me.cboName & """, txtName FROM tblVC WHERE Branche ='" & Me.cboBranchen & "';"

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) & "'"

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"), ", ")