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 "MyAccessDB.mdb". 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 "logfile.txt" as the file name instead of "MyAccessDB.mdb for testing purposes):
Option Explicit
Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (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, "Open", DocName, _
"", "c:\", SW_SHOWNORMAL)
Exit Function
StartDoc_Error:
MsgBox "Error: " & Err & " " & Error
Exit Function
End Function
Sub startdb()
StartDoc ("logfile.txt"
End Sub
That's it! Thanks!
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 "MyAccessDB.mdb". 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 "logfile.txt" as the file name instead of "MyAccessDB.mdb for testing purposes):
Option Explicit
Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (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, "Open", DocName, _
"", "c:\", SW_SHOWNORMAL)
Exit Function
StartDoc_Error:
MsgBox "Error: " & Err & " " & Error
Exit Function
End Function
Sub startdb()
StartDoc ("logfile.txt"
End Sub
That's it! Thanks!