Microsoft Project pool resources - count problem - vba

code from learn.microsoft:
Dim R As Long, Names As String
For R = 1 To ActiveProject.Resources.Count
Names = ActiveProject.Resources(R).Name & ", " & Names
Next R
MsgBox Names
Works great when resources are defined in project file.
But when you use resources only in subprojects Resources collection is empty.
Adding new resource manually does not any changes - still count 0.
Using ribbon and Add Resources - counts this resource but other not.
How can I count resources from subprojects in main project?
When I terminate link to subprojects Resources collection count correctly.
Any ideas?

Sebastian, There is no error. I assume the "main project" you reference is a dynamic master. In a master project, subprojects are not part of the master, rather, the master contains pointers to each subproject. So when you run code in a master that loops through the Active.Project, the loop is looking for objects in the master and the master has no resource objects. Here is a modified version of your macro that will show the names of all resources in the resource pool, assuming all subprojects are using the pool. If there is a mixture of subprojects sharing and/or using their own resources the code will need to be modified.
Names As String
Dim Res As Resource
For Each Res In ActiveProject.Subprojects(1).SourceProject.Resources
Names = Res.Name & ", " & Names
Next Res
MsgBox Names
End Sub

The solution given by john-project solves the problem.
Browsing a resource collection with Resources collection remains problematic in one more situation: the project file contains its own resources separated by a blank line inserted with the insert key.
Such a line has an identifier but all fields are empty. Browsing resources using a collection generates an error (e.g. when reading the resource name).

Related

Ms Project VBA Macro Organiser to subproject copy issue

I have a simple line of code that attempts to copy text field via project organiser from a Master project/Global.mpt to subproject within the master project (active project). I have tried multiple ways but i'm failing either with
'Run-time error 1101, the file Schedule 1" was not found Or, "This value is not valid in this situation, check the field to see if it requires a text, date or a number, and that you typed the information correctly".
Appreciate your help. Thanks
'OrganizerMoveItem Type:=pjFields, FileName:="MASTER SCHEDULE.mpp", ToFileName:=" Schedule1.mpp",
Name:="Text27"
'OrganizerMoveItem Type:=pjFields, FileName:="C:\xx\MASTER SCHEDULE.mpp", _
'ToFileName:=ActiveProject, Name:="T27(Text27)"
OrganizerMoveItem Type:=9, FileName:="GLOBAL.MPT", _
ToFileName:=ActiveProject.Subprojects("Schedule1.mpp"), Name:="T27"
The issue is that the subproject file needs to be open in order to use the Organizer to move customizations into it. Viewing the subproject's tasks in the master schedule is not the same as the subproject file being open.
This code will loop through the subprojects and copy the customized Text27 field to each one by opening it, using the Organizer, then closing and saving it.
Sub CopyCustomFieldToSubprojects()
Dim master As Project
Set master = ActiveProject
Dim prj As Subproject
For Each prj In master.Subprojects
FileOpenEx prj.Path
Projects(prj.SourceProject.Name).Activate
Application.Alerts False
OrganizerMoveItem Type:=pjFields, FileName:=master.Name _
, ToFileName:=ActiveProject.Name, Name:="T27 (Text27)"
Application.Alerts False
FileCloseEx pjSave
Next prj
End Sub
Note that the OrganizerMoveItem method expects a file name (string) for the FileName and ToFileName parameters rather than a Project object (e.g. Filename:=master.Name).

SSIS variable lookup of existing subfolders by name

I have added a File System Task to an SSIS package for the purpose of creating 7 new subfolders in 24 existing directory subfolders based on a purchase order number.
The first var titled MainFolderPath is to the main system where the existing and new subfolders reside. Additionally I have created a var called FolderName that creates a subfolder with the PO #, and then creates 7 new subfolders in the PO # subfolder.
The part I am struggling with is creating a var that will create the PO and 7 new subfolders in each of the 24 existing subfolders at the same time.
Below is my example:
Var 1: var.MainFolderPath Type – String
\\10.xxx.xx.xxx\sales\subsystem
Var 3: var.FolderName Type – String
+ [#User::var_PurchaseOrder] + "1. Estimates" + "2. Approval" + "3. Legal" + "Processing" + "5. Fulfilment" + "6. Shipping" + "7. Billing"
In the subsystem are 24 existing subfolders, e.g. engines, tires, electrical, etc. The missing var finds those existing subfolders by name for the var.PurchaseOrder to create the new PO # folder and 7 new subfolders.
I hope this structure makes sense, and would appreciate any assistance on how I can make this work.
I would store the names of the folders in a SQL Server table and then use an Execute SQL Task to select these into an object variable (set ResultSet to 'Full result set' and then map the result set to the object variable [set the Result Name to "0"]). (You're essentially putting a single-column result set into an object variable.)
You can then use a Foreach Loop to iterate over this collection using a Foreach ADO Enumerator, mapping each result to a string variable, which can then be included as part of your Create Directory path.
Then simply add the File System Task for Create Directory into the Loop.
I'm not sure this is what you need in its entirety, as you also mentioned 24 sub-directories, but this design pattern will be able to handle any level of complexity in that regard, e.g., you may end up with a Loop (for the 7 folders) within another Loop (for the 24 sub-directories).

VBA - Finding folder inside a directory and returning the path of that folder

I am using excel vba to make an application that acts as a job card. User will fill in relevant fields, press a button to update a running summary of costs, as well as generate a printable pdf of the job card. I have very limited experience in coding (a semester of java 4 years ago) so i am relatively new to this.
Currently, the application automatically updates the summary file and can open a word template file and fill it in with information from the input fields, so it mostly works. I have realised an issue in the way it is finding the summary files, in that as soon as a folder name does not align with the way i am constructing the folder paths in the app, it will return errors.
At the moment I am going into folders like this:
templatePath = "C:\SERVICE\Card Template.doc"
If cbxType.Text = "Plant" Then
savePath = "C:\SERVICE\0.1 PLANT\" & cbxNo.Text & " - " & txtMakeModel.Text & " " & txtRego.Text & "\0.2 SERVICE SHEETS\"
ElseIf cbxType.Text = "Vehicle" Then
savePath = "C:\SERVICE\0.2 VEHICLES\"
End If
The directory is constructed from text and combo boxes which are populated once the user chooses a type (plant, vehicle, etc.) and then ID, which fills in boxes for model name, registration number, hours etc.
I am after a piece of code that can iterate through a given directory, searching the folder names for a string and returning the path of that folder. Each folder begins with the ID number, so I figure I can search folder names for that but I am not sure how to construct the loop. Any help with this, or alternative ideas would be appreciated. If it isn't too much to ask I'd also like a little bit of an explanation on how it works.

How to work out how many Folder are in a folder vb.net

I want to be able to would out how many folders there are in a folder. This is because i was to make a back up system and i want to be able to say if there is already 5 folders in the folder then delete the oldest and add the new one in. How would i do this?
To start with, you can get a collection of all the subdirectories using the My.Computer.FileSystem.GetDirectories method. It should be trivial to find out how many items exist in that collection.
If you need to search for the oldest one then use the My.Computer.FileSystem.GetFileInfo method on each of the items from the previous API call. The returned FileInfo object will contain the creation time amongst other information. Hope this helps!
I worked it out,
Dim counter As _
System.Collections.ObjectModel.ReadOnlyCollection(Of String)
counter = My.Computer.FileSystem.GetDirectories("C:\test")
MsgBox("number of folders is " & CStr(counter.Count))
I just got the file one and modified it a bit :).... Now to work out the date system

How to get file size from within TSQL (path specified in column) in SSRS 2005

I need to get the Folder size and display the info on a report (SSRS). I need to do this for a number of Databases (loop!). These DB's are websites' backends.
Are any samples available for this? Does xp_filesize and the like the right solution?
Looking at the question and Tomalak's response, and I'm assuming the reporting server will be able to reach the folders held in the DB:
Firstly set up the query to get you back the result-set of paths - I assume you'll have no trouble with this part. Next you'll need to add a custom code function to your report: http://msdn.microsoft.com/en-us/library/ms155798.aspx - This function will take the folder path as a parameter, and pass back the size of the folder. You'll have to write in VB.Net if you want to embed the code in the report, or you could code up a DLL and bring that in.
An example VB.Net code block (Remember you may need to prefix objects with System.IO.) http://www.freevbcode.com/ShowCode.asp?ID=4287
Public Shared Function GetFolderSize(ByVal DirPath As String, _
Optional IncludeSubFolders as Boolean = True) As Long
Dim lngDirSize As Long
Dim objFileInfo As FileInfo
Dim objDir As DirectoryInfo = New DirectoryInfo(DirPath)
Dim objSubFolder As DirectoryInfo
Try
'add length of each file
For Each objFileInfo In objDir.GetFiles()
lngDirSize += objFileInfo.Length
Next
'call recursively to get sub folders
'if you don't want this set optional
'parameter to false
If IncludeSubFolders then
For Each objSubFolder In objDir.GetDirectories()
lngDirSize += GetFolderSize(objSubFolder.FullName)
Next
End if
Catch Ex As Exception
End Try
Return lngDirSize
End Function
Now, in your report, in your table, you'd have for the cell that shows the folder size an expression something like:
=Code.GetFolderSize(Fields!FolderPath.Value)
I doubt this approach will be performant for a manually-viewed report, but you might get away with it for small result sets, or a scheduled report delivered by email?
Oh, and this piece suggests you 'may' run into permissions issues using System.IO from within RS: http://blogs.sqlxml.org/bryantlikes/pages/824.aspx
Could you clarify who should do what in your scenario? Do you want SQL Server do get the info or do you want Reporting Server do that?
What exactly do you mean by "folder size"? Is "one folder, sum up each file" enough or does it need to be recursive? Either way, I'd go for a little custom .NET function that uses System.IO.Directory and it's relatives.
I'd consider splitting this into two pieces, maybe a Windows Service to scan the directories and aggregate the data into a database, then use SSRS to report on the database as usual.
The reason I suggest this is to use master..xp_filesize and it's kin the account the SQL Server service is starting with needs access to the paths to be scanned. Once this turns into accessing paths on other machines I'd be less comfortable with the security implications of that.
Hope this helps
In SSRS you can to do this with the help of custom data extension. U need give the path for the datasource as your folder name and it will retrive your files and its related informations and displayed
For further reference and custom dll use this
http://www.devx.com/dbzone/Article/31336/0/page/4
I have done this earlier.
Note: you have to make related changes to Report Designer and Report Manager configuration files.