?
Solved

How to reference a file folder with a variable extension?

Posted on 2004-08-30
12
Medium Priority
?
229 Views
Last Modified: 2008-03-17
I have the following function in a program which creates a new directory(folder) for the current day. This program runs once a day. So everyday it would create a new folder. Example:

s:\temp\MSR\30-Aug-04
s:\temp\MSR\31-Aug-04
s:\temp\MSR\01-Sep-04
and so on....

Function Make_Folder()
 Dim Folder As String
 Folder = "s:\temp\MSR\" & Format(Now, "d-mmmm-yy")
 If Dir(Folder, vbDirectory) = "" Then
    MkDir Folder
 End If
End Function

Then I have the following '.exe' which gets triggered by a rule in Outlook to look in the 'InBox' folder for certain type of messages based on the 'Subject' text that I want stored in the current day folder based on it being created by the above.
I'm not sure how to assign a variable to the following statement below:

oMessage.SaveAs "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "Incident Alert.msg", olMSG

The way I have it now it's adding the: Format(Now, "d-mmmm-yy") to the .msg. So it ends up looking like this:

30-Aug-04Incident Alert.msg

I want the message to go into the current day folder. And then the next day the .msg's would go to another new folder that was created.


Private Sub Main()
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oMessage As Outlook.MailItem
Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)


For Each oMessage In oFldr.Items
    If InStr(1, oMessage.Subject, "Incident Alert") > 0 Then
    oMessage.SaveAs "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "Incident Alert.msg", olMSG
    oMessage.Delete
End If

    Next oMessage
 
    Set oMessage = Nothing
    Set oFldr = Nothing
    Set oNs = Nothing
    Set oOutlook = Nothing
   
End Sub

Any Ideas??
0
Comment
Question by:Richard Kreidl
  • 5
  • 5
  • 2
12 Comments
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11932032
oMessage.SaveAs "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "\Incident Alert.msg", olMSG
0
 
LVL 2

Expert Comment

by:x50Fade
ID: 11932189
Yup...you just forgot your slash before your filename....as mladenovicz pointed out
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 11932320
I get an internal application error when I added the slash.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:x50Fade
ID: 11932355
Are you sure that s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") exists...have you allready created it?
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11932362
Private Sub Main()
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oMessage As Outlook.MailItem
Dim FileName As String

Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)


For Each oMessage In oFldr.Items
    If InStr(1, oMessage.Subject, "Incident Alert") > 0 Then
    FileName = "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "Incident Alert.msg"
    Debug.Print FileName
    oMessage.SaveAs FileName, olMSG
    oMessage.Delete
End If

    Next oMessage
 
    Set oMessage = Nothing
    Set oFldr = Nothing
    Set oNs = Nothing
    Set oOutlook = Nothing
   
End Sub

Can you post content of immediate window here?
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11932386
Function Make_Folder()
 Dim Folder As String
 Folder = "s:\temp\MSR\" & Format(Now, "d-mmmm-yy")
 If Dir(Folder, vbDirectory) = "" Then
    MkDir Folder
 End If
End Function

Shouldn't this

 Folder = "s:\temp\MSR\" & Format(Now, "d-mmmm-yy")

be

 Folder = "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy")
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 11932406
Here it is:

s:\temp\MSR\Incident Alert\30-August-04Incident Alert.msg
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 11932443
Here it is with a slash before the file name:

s:\temp\MSR\Incident Alert\30-August-04\Incident Alert.msg
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11932459
Does folder s:\temp\MSR\Incident Alert\30-August-04 exists?
0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 1000 total points
ID: 11932472
if it does not exist then

For Each oMessage In oFldr.Items
    If InStr(1, oMessage.Subject, "Incident Alert") > 0 Then
    Call Make_Folder
    oMessage.SaveAs "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "Incident Alert.msg", olMSG
    oMessage.Delete
End If
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 11932565
I'm still getting an internal application error. Here is the code I'm testing with:
Private Sub Main()
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oMessage As Outlook.MailItem
Dim FileName As String

Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)

For Each oMessage In oFldr.Items
    If InStr(1, oMessage.Subject, "Incident Alert") > 0 Then
    Call Make_Folder
    oMessage.SaveAs "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "\Incident Alert.msg", olMSG
    oMessage.Delete
End If


    Next oMessage
 
    Set oMessage = Nothing
    Set oFldr = Nothing
    Set oNs = Nothing
    Set oOutlook = Nothing
   
End Sub

Function Make_Folder()
 Dim Folder As String
 Folder = "s:\group0k\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy")
 If Dir(Folder, vbDirectory) = "" Then
    MkDir Folder
 End If
End Function

0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 11932595
I found the problem I had one of the folders setup wrong. Thanks for all the help
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question