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
Related
I am trying to automate a repetitive manual task for another department. They have a word template several pages long. They have to enter data several times each time they use it. Many of these are repetitive "fields". I thought about setting up custom form fields. But having them go through the navigation and know the field names to update them is not optimal. I found one solution to create a bookmark for each data input, and create links to that bookmark where it needs to be repeated - better but not optimal. I was hoping to create a userform where they can enter all the data and have it populate bookmarks, custom fields, to whatever.
I found a video that does this, but when I try the code, it does not update the bookmark. i created userform with Textbox1, and a CommandButton, and a bookmark in the document called MWDate. The code I am trying to get to work is:
Private Sub CommandButton1_Click()
Dim MWDate As Range
Set MWDate = ActiveDocument.Bookmarks("MWDate").Range
MWDate.Text = Me.TextBox1.Value
Me.Repaint
UserForm1.Hide
End Sub
This is a code example I grabbed and modified from the tutorial video. I don't know what the "Me." is. It does not populate the bookmark, which tells me it is not getting to the repaint line. Nor does it ever get to the hide line.
Anyone have a fix? Or a better way? Thanks for any help you can give.
I have a long list of data, one line for one movement. I need to check the volumes of the movements by location. The locations can be grouped, as some of them has the same criteria for filtering. For doing that I would like to read the cell values into a list and then looping through the original list of data by checking into which group does the location belongs. I don't know how to read the group into a list in a way that then I can check if a cell value matches with any of the items in the original - to be filtered - list.
Can anyone help with it? Also, in case you have any other suggestion for the solution, I appreciate it too.
Thanks!!
Please provide us your own solution or at least a attempts to present your effort. Without any data or code to analyze I can suggest sth like this:
Sub Make_a_List()
Dim TableWithData() as Variant
TableWithData = Range(Cells(1,1),Cells(100,100)) 'Values as example
End Sub
This gives you an table with elements of the specified range. For one row you will get one dimension table.
Then for instance you can make a for loop:
For i=1 to Ubound(TableWithData)
if TableWithData(i) = sth then
do whatever you need
end if
Next i
So far I haven't used VBA with pivot tables. Now I would like to update (refresh) 2 pivot tables and set the filter for the calendar week to the last full week.
My questions / problems here are:
1) Do I actually need the .ClearAllFilters lines or can I set the filter also without it ?
2) Can I check before setting the filter if the corresponding item (e.g. the week number 13) exists in my table ? Otherwise I would try to filter for something that doesn't exist (yet).
3) Do I write the code for this the right way or is there a shorter / better way for this ? E.g. I wasn't sure if With within With would makes sense here.
My code:
Dim varLastSunday As Date, varWeekNumber As Integer
varLastSunday = Date - Weekday(Date, vbUseSystemDayOfWeek)
varWeekNumber = CLng(Format(varLastSunday, "ww"))
Application.ScreenUpdating = False
With Worksheets(4)
.Range("StartColumns").EntireColumn.Hidden = False
.PivotTables("PivotTable9").PivotCache.Refresh
.PivotTables("PivotTable9").PivotFields("WEEK_NUMBER").ClearAllFilters
.PivotTables("PivotTable9").PivotFields("WEEK_NUMBER").CurrentPage = varWeekNumber
.PivotTables("PivotTable10").PivotCache.Refresh
.PivotTables("PivotTable10").PivotFields("week").ClearAllFilters
.PivotTables("PivotTable10").PivotFields("week").CurrentPage = varWeekNumber
End With
Application.ScreenUpdating = True
Because you are dealing with a PageField (i.e. a field that is in the Filters pane and that has "Select Multiple Items" unchecked) then no, I don't believe you need to clear filters. But my advice...just leave it in there...it won't hurt.
Easier simply to put some kind of error handling in your code to pick up any errors if the item doesn't exist. If you simply want to ignore any error, put an On Error Resume Next statement at the top of your block of code. Alternately you may want to advise the user that the PivotTable has not been filtered. If you clarify what you want to do, I'll post a code snippet.
Note that if both these pivottables share the same datasource, you don't need to refresh both caches, because they share a cache. If that's the case, then just get rid of the 2nd Refresh line.
Can you clarify why you are hiding the column? Does it get unhidden later? Is it likely to be unhidden whenever you run this code?
If this is all your code is doing, then I probably wouldn't bother turning off screenupdating. But again, it doesn't really matter.
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.
I'm trying to create a custom script in SSIS 2008 that will loop over the selected input columns and concatenate them so they can be used to create a SHA1 hash. I'm aware of the available custom components but I'm not able to install them on our system at work.
Whilst the example posed here appears to work fine http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/69766/ when I've tested this selected only a few and not all columns I get odd results. The script only seems to work if columns selected are in sequential order. Even when they are in order, after so many records or perhaps the next buffer different MD5 hashes are generated despite the rows being exactly the same throughout my test data.
I've tried to adapt the code from the previous link along with these articles but have had no joy thus far.
http://msdn.microsoft.com/en-us/library/ms136020.aspx
http://agilebi.com/jwelch/2007/06/03/xml-transformations-part-2/
As a starting point this works fine to display the column names that I have selected to be used as inputs
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
For Each inputColumn As IDTSInputColumn100 In Me.ComponentMetaData.InputCollection(0).InputColumnCollection
MsgBox(inputColumn.Name)
Next
End Sub
Building on this I try to get the values using the code below:
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Dim column As IDTSInputColumn100
Dim rowType As Type = Row.GetType()
Dim columnValue As PropertyInfo
Dim testString As String = ""
For Each column In Me.ComponentMetaData.InputCollection(0).InputColumnCollection
columnValue = rowType.GetProperty(column.Name)
testString += columnValue.GetValue(Row, Nothing).ToString()
Next
MsgBox(testString)
End Sub
Unfortunately this does not work and I receive the following error:
I'm sure what I am trying to do is easily achievable though my limited knowledge of VB.net and in particular VB.net in SSIS, I'm struggling. I could define the column names individually as shown here http://timlaqua.com/2012/02/slowly-changing-dimensions-with-md5-hashes-in-ssis/ though I'd like to try out a dynamic method.
Your problem is trying to run ToString() on a NULL value from your database.
Try Convert.ToString(columnValue) instead, it just returns an empty string.
The input columns are not guaranteed to be in the same order each time. So you'll end up getting a different hash any time the metadata in the dataflow changes. I went through the same pain when writing exactly the same script.
Every answer on the net I've found states to build a custom component to be able to do this. No need. I relied on SSIS to generate the indexes to column names when it builds the base classes each time the script component is opened. The caveat is that any time the metadata of the data flow changes, the indexes may change and need to be updated by re-opening and closing the SSIS script component.
You will need to override ProcessInput() to get store a reference to PipelineBuffer, which isn't exposed in ProcessInputRow, where you actually need to use it to access the columns by their index rather than by name.
The list of names and associated indexes are stored in ComponentMetaData.InputCollection[0].InputColumnCollection, which needs to be iterated over and sorted to guarantee same HASH every time.
PS. I posted the answer last year but it vanished, probably because it was in C# rather than VB (kind of irrelevant in SSIS). You can find the code with all ugly details here https://gist.github.com/danieljarolim/e89ff5b41b12383c60c7#file-ssis_sha1-cs