Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I use VB to open a file from Outlook?

Status
Not open for further replies.

demerc

MIS
May 9, 2003
1
US
I have created an access DB "MyAccessDB.mdb" that needs to be run every Monday. Outlook must be open in order for the DB to run correctly. The code below is all I need to make the decision within outlook of whether or not to run my Access DB. (Simply put, if it's Monday and the date of the last report - "logfile.txt" - was more than a week ago, then open "MyAccessDb.mdb")

Sub readfile()
Dim lastDate As String
Open "C:logfile.txt" For Input As #1
Input #1, lastDate
Close #1

If Weekday(Now()) = 2 Then
If lastDate = Date Then

Else
*Open DB*

End If
Else
If lastDate < Date - 7 Then
*Open DB*
Else

End If
End If

End Sub

All I really need is the code that tells outlook to open the file &quot;MyAccessDB.mdb&quot;. I have tried using ShellExecute but that doesn't seem to work. I created the ShellExecute code in Access and it works, but the same code does not work in Outlook (the code that worked in Access is below - I used &quot;logfile.txt&quot; as the file name instead of &quot;MyAccessDB.mdb for testing purposes):

Option Explicit

Declare Function ShellExecute Lib &quot;shell32.dll&quot; Alias _
&quot;ShellExecuteA&quot; (ByVal Hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long

Global Const SW_SHOWNORMAL = 1



Function StartDoc(DocName As String)
On Error GoTo StartDoc_Error

StartDoc = ShellExecute(Application.hWndAccessApp, &quot;Open&quot;, DocName, _
&quot;&quot;, &quot;c:\&quot;, SW_SHOWNORMAL)
Exit Function

StartDoc_Error:
MsgBox &quot;Error: &quot; & Err & &quot; &quot; & Error
Exit Function
End Function

Sub startdb()
StartDoc (&quot;logfile.txt&quot;)
End Sub



That's it! Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top