Outlook 2010 Macro to open an accdb file (1 Viewer)

Salbrox

Registered User.
Local time
Today, 10:00
Joined
Nov 10, 2012
Messages
49
Hi I need to to open a accdb Access Database (2010) when I receive certain emails. I have a macro that needs to run before opening the accdb and I cannot change the order in which the outlook rule runs (the rule can open an application but not after running a script!) I have a rule set up and thought that a VBA script using Application.Followhyperlink or a Shell("Path to accdb file") command would work and neither appear to be supported!

Does anybody know of a way that I could do this? Im at the verge of pulling my hair out right now.

Any help would be much appreciated!
 
Last edited:

pr2-eugin

Super Moderator
Local time
Today, 10:00
Joined
Nov 30, 2011
Messages
8,494
Salbrox, your description might not be completely clear..

What is the rule you have? Does the email have a Link? Or does it have the file? How do you obtain the path of the Access File?
 

Salbrox

Registered User.
Local time
Today, 10:00
Joined
Nov 10, 2012
Messages
49
The accdb file is always in the same folder on my C: drive. The rule moves emails with a specific subject (containing "IFF") into a folder in my inbox called IFF. It then runs a macro which copies excel attachements from the email in the IFF folder to a folder on my C: drive (C:\iff) After this is when i want to open the accdb file. When the accdb file opens it searches that folder for excel files and automatically imports them to a linked database and then closes.

I can't find anywhere online that will describe how to open a file from Outlook. I thought I could use Application.FollowHyperlink in a VBA macro but i can't and either Shell() is not supported or im getting the syntax wrong.

Thanks for your response btw i really appreciate any help i get on this!
 

Salbrox

Registered User.
Local time
Today, 10:00
Joined
Nov 10, 2012
Messages
49
I did it!
Code:
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim cmd As String
saveFolder = "C:\IFF\ATTCH"
    For Each objAtt In itm.Attachments
        objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
        Set objAtt = Nothing
    Next
    cmd = "msaccess " & Chr(34) & "C:\IFF\IFF.accdb" & Chr(34) & " " 'Opens the database
    Status = Shell(cmd, vbNormalFocus)
End Sub
 

pr2-eugin

Super Moderator
Local time
Today, 10:00
Joined
Nov 30, 2011
Messages
8,494
Sorry about not replying earlier, I normally do not go online over the weekend.. But, am glad you have it all sorted.. :)
 

Users who are viewing this thread

Top Bottom