Solved

How to reference a file folder with a variable extension?

Posted on 2004-08-30
12
219 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:rkckjk
  • 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:rkckjk
ID: 11932320
I get an internal application error when I added the slash.
0
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Author Comment

by:rkckjk
ID: 11932406
Here it is:

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

Author Comment

by:rkckjk
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 250 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:rkckjk
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:rkckjk
ID: 11932595
I found the problem I had one of the folders setup wrong. Thanks for all the help
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now