How to Create a Report Containing 3 DataTables - vb.net

Goal
I want to create a report that will contain three DataTables (unless doable with 1 DataTable, you tell me!). The following screenshot displays ConveyorNames, OptionNames, ConveyorOptionPrices:
Problem
The problem I am facing is I cannot seem to figure out how I will go about displaying horizontal conveyor Names (Conveyor1, Conveyor2, Conveyor3, ...) horizontally while displaying OptionNames (Optn1, Optn2, Optn3, ...) vertically; while at the same time populating the price for Conveyor1 and Optn1 (and so on) in their relative cells.
I'd like to provide something that I have tried, but nothing conclusive as of yet would be useful here. To be honest, I don't even know where to start. If anyone can point me in the right direction, I'll be very thankful!

I figured it out using only 1 DataTable. You must create a Matrix and attach this DataTable to it.
Related to my example, my DataTable will contain the following fields: ConveyorName, OptionName, and OptionPrice like so:
Afterwards, I just loop through my three DataTables and fill in the fields like so:
For Each convRow As ds1.dtConveyorsRow In dsConv.dtConveyors
For Each optnRow As ds2.dtOptionsRow In dsOptn.dtOptions
For Each convOptnRow As ds3.dtConvOptnsRow In dsConvOptn.dtConvOptns.Select("FK_Conveyor=" & convRow.PK_Conveyor & " AND FK_Option=" & optnRow.PK_Option)
dtRpt.AddConvOptnRow(convRow.ConveyorName, optnRow.Name, convOptnRow.Price)
Next
Next
Next
Which populates it exactly as I showed in my question's picture.

Related

How to create 2D visualization from Access data set

I have a data set containing the following fields:
rack, rack_type, box_number, box_label, row, column
Each rack in the real world is basically a 2D grid with cells, each cell containing an object(a small box in this case). Each box will be associated with a specific position in the rack based on row and column. The size of the grid (number of rows/columns) is different based on rack_type
Is there a way to create a visual representation of these racks from the data supplied above? Specifically, I am looking to create a grid (as if you were looking at it in real life) where each cell shows some text--box_number and box_label in this case. I've been searching for hours on Google to no avail and I don't know if I'm even asking the question correctly. From what I can tell, the normal report/form features in Access do not support such a configuration of data. I'm wondering if there is some VBA solution, since I have some experience with VBA in Excel. Please let me know if this is incomprehensible gibberish.
If your racks has a finite maximum number of boxes in any configuration then you might consider this solution:
Let's say that any of your racks contains at most R boxes
create a form F
open F and add to it R text boxes B (they are not linked to anything)
save the form
now in VBA, on loading a rack you can iterate on each box and use some code to position each each of them on the form, show or hide it, and finally set its size!
Basically you've added to your form more boxes than a typical rack configuration would normally need, and by doing so you can hide some of them when not needed. You have this limit because you cannot create and add at runtime new text boxes to a form in VBA (it should work for reports too).
Note that you could use also other types of objects, text boxes are useful if you want to edit the text inside of them, otherwise you could use a label or anything that suits your needs the most (combo box... for example).
Basic methods that you might want to look at:
cell1.Height = 100
cell1.Visible = Not cell1.Visible
cell1.Move Left:=0, Top:=0, Width:=400, Height:=3000
Anyhow if you get more in details, by giving some examples of your racks we might be able to come with a more detailed solution.

Display certain text based off of Data Selection

I'm making a form that shows all of the parts in our database (from our master components table named TAGS). All of the values are displaying fine because it's pulling from the TAG table. The thing is, when the table was created, they never entered the descriptions of each component type.
For example, in the table, TagLabel "CON" should have description "Condensers" on the report for clarity sake (some of the tag labels aren't very intuitive).
I'm trying to use VBA code in order to format a textbox (TagDescription) next to the TagLabel box that displays the descriptions based off of what the TagLabel is. The "simple" but horribly tedious solution to this is just going through the TAG table and manually adding in a description column.
I'm trying to do something like this to avoid that:
Private Sub Report_Page()
If Me.TagLabel = "CON" Then
Set Me.TagDescription = "Condensers"
End If
End Sub
I'm sure it's just a simple syntax fix, but I've tried a couple things that don't work, such as adding .value and .text to the end of Me.TagLabel etc. Thanks for all your help in advance!
This is probably the syntax you're looking for, but I'm sure if if you'll get the effect you want. It sounds like a very ugly solution.
Private Sub Report_Page()
If TagLabel = "CON" Then
TagDescription = "Condensers"
End If
End Sub
If you're going to go to all the trouble of building a big IF block for each possible TagLabel, you should probably bite the bullet and do it the right way with a lookup table.
Just create a new column in a Tags lookup table and update the tags - much less typing then doing all the code you're talking about. Then it's easy to join the table to the report query and your textbox will fill automatically

Formatting issues duplicating table

Forward
I am making a "label program" that will print waybill information. Consists of a table in Word on a custom 3x5 inch document with 0 margins.
I currently have a simple form that, if you need copies, it will edit one of the cells so that each time it prints the "pieces count" is incremented. 1of10, 2of10, 3of10.....
While that worked the code submitted a separate print job for each "label". That created a problem for the end user where they would have to wait about 5-10 seconds between print jobs. When printing a couple of hundred of these at a time those seconds can add up.
Corrective solution
To try an alleviate this problem I wanted to make copies of the table so that 100 labels would be printed as one 100 page document. Found several solutions for copying pages of text but I have tables which complicated things. The closest solution I have found was:
With ActiveDocument
.Tables(1).Range.Copy
.Range.Select
'.Range.InsertAfter (Chr(11))
Selection.Collapse wdCollapseEnd
Selection.Paste
End With
And this does make a perfect copy of the table however it is merging the tables together. So if I wanted to loop this to create several more labels it would be doubling up the results every time since the code above just copies the first tabel.
To try and fix that issue I added a line break (vertical tab) before the paste. You will see that as the commented out line in the above snippet. This breaks up the tables but adds too much whitespace in between.
Page breaks seems like the solution here. While those did make the table break up they ended up creating a blank page in between each label which I was having enough of a time clearing from the GUI let alone in VBA.
The actual question
How can I take a table that is perfectly designed to fit on one 3x5 inch page and duplicate it X times. The caveat is I need to be able to find the cell programically that contains the pieces text. Currently I can use these absolute reference for the first table
ActiveDocument.Tables(1).Cell(5, 1).Range.Text
So if I had 3 tables for instance I need to be able to call each table and edit the text of the Cell(5, 1).
In case you ask
I know this functionality is better placed inside actual label programs like Bartender but those cost money that the company will not allocate for the only label my company uses.
The right concept was there. We needed to add a break in between the tables to disassociate them. Adding the vertical tab Chr(11) was obviously not the correct way to do it.
A proper section break would be the route to go here. Looking at MSDN you can see there are multiple types of section breaks. After testing a desirable outcome was acheived from using wdSectionBreakNextPage which is a "Section break on next page."
Basically just needed to add one line to the above code.
With ActiveDocument
.Tables(1).Range.Copy
.Range.Select
End With
With Selection
.Collapse wdCollapseEnd
.InsertBreak (wdSectionBreakNextPage)
.Paste
End With
I hate the use of Selection and I am going to look into that but for now this does function properly.
Since the tables are not single units we are able to query .Tables in order to edit each page individually.

Development DropDowns List error on empty value

I have a simple dropdown list named DD8. It uses 50 rows as control, the problem is that for now only 45 rows are used. That means that in the dropdown list there are 5 empty rows. The problem is that if someone select one empty row, or don't select anything (default is empty) the fallowing code will show error :
With Worksheets(1)
NameProf = .DropDowns("DD8").List _
(.DropDowns("DD8").ListIndex)
End With
I tried things like if .DropDowns("DD8").List (.DropDowns("DD8").ListIndex) != "" but ofc, it shows error. I searched how to select only used rows with the DropDown list of the development tab but it doesn't seem to be possible.
I have to select 50 rows because new customers can be added.
Do you know how it can be achieved ?
If new customers can be added, then I imagine, and hope for you, that it goes above 50.... so it's not just an issue of having 5 blanks for now to not be an option, but also allowing customers 50-2,483 also be on there when they come along. ---- Without more details on your code, I believe this suggestion should help 'guide' you but not immediately solve your issue.
Essentially, whenever you call to have your dropdown populated, you want some code to find the last row of data in the customers column, and then assign your dropdown to populate with the starting row of your customers to the lastrow. This way no matter how many customers you have 2, 48, 189... they will show in your dropdown without that issue occurring. A simple google search will yield how to find the last row in excel.
Sorry I couldn't just bust out the code to make it work for you right this second, but I think this should be a good starting point for you.

How to move one column to the end in Pivot table with VBA?

I create a pirvot table, but the colunm order is not what I wanted. I want to move one column to right end. I can do it in Excel, but don't know how to do it with VBA.
In Excel, can do in this way--active the column header which you want to move, click right-hand button, choose Move, Move "--" to end.
Record Macro--when record Macro, it just shows the exact position, just like,
ActiveSheet.PivotTables("PivotTable16").PivotFields("wk").PivotItems("#VALUE!") _
.Position = 12
But I want to use the Macro in other files, maybe the end position is not 12. Then the Macro can't be used.
Hope can get help here. How to do it to move the colunm to end by VBA? Thanks.
I hope I get you right.
You can get the end position by
ActiveSheet.PivotTables("PivotTable1").PivotFields("whatever").PivotItems.count
Basically it returns the number of items for a label
Edited
So you could do like
Dim total as Integer
total = ActiveSheet.PivotTables("PivotTable1").PivotFields("whatever").PivotItems.count
ActiveSheet.PivotTables("PivotTable1").PivotFields("whatever").PivotItems("whatever").position = total
Just a random note to anyone that comes across this and runs into the same issue I did. If in your macro you're hiding fields, it's going to give you an error. Don't use this code as the last thing you do when setting up your pivot table. Use this code, let it move to the bottom position, THEN have your code to hide your fields. If you hide fields first, it'll count the hidden fields then try to move it outside your pivot table and cause an error.