Outlook starts countdown when sending email

azlan

Registered User.
Local time
Today, 02:54
Joined
Aug 14, 2014
Messages
39
I have access db sending report with outlook every Monday.
But the problem is if outlook is open when I start the db, email goes in to outgoing folder and msg box of outlook opens saying " outlook will close after countdown if I do not hit the "DO NOT EXIT" button or "EXIT AND SEND LATER" button.
If I hit "EXIT AND SEND LATER" button, it sends next time I open the outlook.

Is it possible to prevent outlook doing this?
 
here is the code for sending on load event of main form.
Code:
Private Sub Form_Load()
If Weekday(Now) = vbFriday Then
If DCount("*", "tbl_emailLog", "[sentDate] = #" & Format(Now, "dd\/mm\/yyyy") & "#") = 0 Then

'send email
On Error GoTo ErrTrap
    
        P_RaporuGonder _
                Nz("BirSonrakiBakımRaporu", ""), Nz("hakki.bulut@karinsaat.com.tr; ottoman.ulubatli@gmail.com", ""), Nz("Bir Sonraki Bakım Raporu", ""), Nz("", "")
    
    
 CurrentDb.Execute ("INSERT into tbl_emailLog (sentDate) select date()")
    
    'MsgBox "Bitti" & vbCrLf & _
                '" " & _
                '"", vbOKOnly, "Gönderme İşlemi"
    On Error Resume Next


ExitPoint:
    DoCmd.Hourglass False
    On Error GoTo 0
    Exit Sub
        
ErrTrap:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitPoint



End If

End If

End Sub

And other code behind;

Code:
Option Compare Database
Option Explicit

Private Const RaporDosyasi As String = "Raporlar"
Private Const Yolbelirle As String = "*^*"

Sub P_Mailgövdesinde_gönder(MailSubject As String, _
                                            TxtBody As String, _
                                            MailAddress As String) 'değişkenler mail metni , mail adresi ve konu
On Error GoTo ErrTrap
    ' Posta göndermeden önce HTML dosyasını outlook gövdesine uyacak
    Dim olk As Outlook.Application
    Dim msg As Outlook.MailItem
    
    ' outlook açıksa kullan,açık değilse yeni sayfa aç
    
    Err.Clear
    On Error Resume Next
    Set olk = GetObject(, "Outlook.Application")
    If Err.Number <> 0 Then
        Set olk = New Outlook.Application
    End If
    Err.Clear
    On Error GoTo ErrTrap
    
    Set msg = olk.CreateItem(olMailItem)
    With msg 'With yapısı kısaca, aynı koleksiyona ait komut yapılarını kullanarak hazırladığımız kodları kısaltmamızı sağlar..
        .Display
        .To = MailAddress
        .Subject = MailSubject
        .BodyFormat = olFormatHTML
        .HTMLBody = TxtBody
        .To = MailAddress
    End With

    ' mesajı gönder
    On Error Resume Next
    msg.Send

    '  kullanıcı mesaj sonrası uyarı versin
    

ExitPoint:
    On Error Resume Next
    olk.Quit
    Set msg = Nothing
    Set olk = Nothing
    On Error GoTo 0
    Exit Sub
        
ErrTrap:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitPoint
End Sub
Function Fn_DosyaOlustur(ByVal FolderPath _
                                    As String) As Integer
    On Error GoTo ErrTrap
    Dim fso As Scripting.FileSystemObject
    Dim fdr As Scripting.Folder
    
    Set fso = New Scripting.FileSystemObject
    
    'Klasörün var olup olmadığını kontrol edin
    If Not fso.FolderExists(FolderPath) Then
       'Gerekirse bir klasör oluşturun
       Set fdr = fso.CreateFolder(FolderPath)
    End If
    
    If fso.FolderExists(FolderPath) Then
       Fn_DosyaOlustur = 1
    Else
        Fn_DosyaOlustur = 0
    End If
    
ExitPoint:
    On Error Resume Next
    Set fdr = Nothing
    Set fso = Nothing
    On Error GoTo 0
    Exit Function

ErrTrap:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitPoint
End Function

Sub P_RaporuGonder( _
                            RepName As String, MailAddress As String, MailSubject As String, Preface As String)
                            
On Error GoTo ErrTrap
    '
    
    Dim FilePathWord As String
    Dim FilePathHTML As String
    Dim RepFolderPath As String
    Dim TxtBody As String
    
    Dim fso As FileSystemObject
    Dim fe As TextStream
    
    Dim wdp As Word.Application
    Dim doc As Word.Document
    
    'Klasör oluşturun (varsa kullan)
    RepFolderPath = CurrentProject.path & _
                                "\" & RaporDosyasi
    Call Fn_DosyaOlustur(RepFolderPath)
    
    ' Rapor çıktı dosyaları için yolunu ayarlayın.
    FilePathWord = RepFolderPath & "\" & _
                                RepName & ".DOC"
    FilePathHTML = RepFolderPath & "\" & _
                                RepName & ".HTML"
    
    ' varsa  dosyaları silin
    On Error Resume Next
    Kill FilePathWord
    Kill FilePathHTML
    On Error GoTo ErrTrap
     
    '
    
    DoCmd.OutputTo acOutputReport, RepName, _
                        acFormatRTF, FilePathWord, False
    
    Err.Clear
    On Error Resume Next
    Set wdp = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        Set wdp = New Word.Application
    End If
    Err.Clear
    On Error GoTo ErrTrap
    
    ' Varsa Word uygulamasını kullanın,yoksa yeni
    Set doc = wdp.Documents.Open(FilePathWord)
    P_metinekle wdp.Selection, Preface
    doc.Save
            
    ' word dosyaını html kaydet
    doc.SaveAs FileName:=FilePathHTML, _
                        FileFormat:=wdFormatHTML
        
    doc.Close
    wdp.Quit False
    Set doc = Nothing
    Set wdp = Nothing
    Set fso = New FileSystemObject
    Set fe = fso.OpenTextFile(FilePathHTML, ForReading)
    TxtBody = Nz(fe.ReadAll, "")
    TxtBody = Replace(TxtBody, Yolbelirle, "")
    

                        
    P_Mailgövdesinde_gönder MailSubject, TxtBody, MailAddress
        
ExitPoint:
    On Error Resume Next
    Set fe = Nothing
    Set fso = Nothing
    On Error GoTo 0
    Exit Sub
    
ErrTrap:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitPoint
End Sub



Sub Lütfen_bekleyiniz(ByVal Tmr As Long)
On Error GoTo ErrTrap

    Dim Cnt As Long

    For Cnt = 1 To Tmr
        DoEvents
    Next

ExitPoint:
    On Error GoTo 0
    Exit Sub

ErrTrap:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitPoint
End Sub

Sub P_metinekle(sel As Word.Selection, _
                                        Preface As String)
    On Error Resume Next
    ' Burada mailin başına gelecek metin
    ' word document
    With sel
        .HomeKey Unit:=wdStory 'sayfa başı home
        .TypeParagraph 'bunlar
        .TypeParagraph 'üstten boşluk 2 enter yani
        .MoveUp Unit:=wdLine, Count:=2 'MoveUp (Birimi, sayın uzatın)wdLine, wdParagraph, wdWindow veya wdScreen
        .TypeText Text:=Preface
        .TypeParagraph 'alttan 1 boşluk
        .HomeKey Unit:=wdStory, Extend:=wdExtend
        With .Font
            .Name = "Arial Narrow" 'yazı tipi
            .Size = 11 'yazı boyutu
            .Bold = False 'kalın
            .Italic = False 'yatık
            .Underline = False 'altçizgi
            .Color = False 'yazı rengi
        End With
    End With
    
    
    Set sel = Nothing
    On Error GoTo 0
End Sub
 
I *think* it's this part...

Code:
ExitPoint:
On Error Resume Next
olk.Quit
Set msg = Nothing
Set olk = Nothing
On Error GoTo 0
Exit Sub

However, because I am not understanding everything I can't be sure. I would make a copy and try commenting that portion out and seeing if that stops it.
 
Dear Gina,
Thank you for your help. Can you help me with another thing.
I have a single record table and on that, there is OLE object field which contains one word document in that record. Is there a way to open that word document with a button. If so what would be the code for that button.
 
Thank You Gina,
But this code assumes that button will be on the same form generated from the table OLE field belongs. But on my db my form that button is on and the table is different, so I couldn't figure out how to change the code. or is it even possible??
 
Last edited:
Ah, don't think that's possible, you need to have the OLE field on the same Form as the Command Button.
 
Actually I want to have some kind of instructions page and I want it to be embedded in DB, is there any other way to do it??
 
Yes. But I write the help and it is a little bit long.
 
And might need modifying time to time..
 
Well, why not just put a Help Command Button that points to your Word document. Then you could Bookmarks to the appropriate section so your Users don't have to *page thru* the document to get to their section. And, you can still modify the document whenever you want.

Your way is not going to work... sorry.
 
What you are saying is, the word document won't be embedded to DB, correct?
If so, how do I open it, I mean the code behind the button?
And how this bookmarking work?
 
I found the code but, the word doc. opens minimized, how can I set it to not open minimized.
Code:
Private Sub Komut75_Click()
 Dim LWordDoc As String
   Dim oApp As Object
   
   'Path to the word document
   LWordDoc = "C:\Users\hakki.bulut\Desktop\çalışma\envanter yönetimi\Final\outlook test\Envanter Kodlama Talimatı.docm"
   
   If Dir(LWordDoc) = "" Then
      MsgBox "Dosya Bulunamadı"
      
   Else
      'Create an instance of MS Word
      Set oApp = CreateObject(Class:="Word.Application")
      oApp.Visible = True
      
      'Open the Document
      oApp.Documents.Open FileName:=LWordDoc
   End If
End Sub
 
Dear Gina,
Can you please help me with this word file opening minimized.
 
I have found the solution and wanted to share:
1) Add the Word doc to a form as an embedded object in an Unbound Object Frame (tick: add "as icon")
2) Set this Unbound Object Frame (icon) to hidden
3) Button "on click" code:
Code:

Code:
Private Sub btnLaunchWordDoc_Click()     With Me.OLEUnbound1  'Name of Unbound Object Frame         .Action = acOLEActivate         .Verb = acOLEVerbOpen     End With End Sub
 
Hmm, got tied up yesterday but I see you found some code! To open maximized try...

Code:
oApp.Application.ActiveDocument.ActiveWindow.WindowState=wdWindowStateMaximize
 
Thank you for your answer Gina.
I have yet another problem to solve.
I am trying to concatenate four different field(all are text) from 3 different table ( all related) in to one field in one of 3 tables to generate bar-code number automatically with query. But I am getting "Type mismatch in JOIN expression. (Error 3615)" here is the SQL;
Code:
SELECT Assets.AyniUrunNumarasi, Marka.MarkaKodu, [Asset Categories].EnvanterSinifiKodu, EnvanterAdi.EnvanterAdiKodu, [EnvanterSinifiKodu] & "" & [MarkaKodu] & "" & [EnvanterAdiKodu] & "" & [AyniUrunNumarasi] AS İfade1
FROM Marka RIGHT JOIN (EnvanterAdi RIGHT JOIN ([Asset Categories] RIGHT JOIN Assets ON [Asset Categories].[AssetCategoryID] = Assets.[AssetCategoryID]) ON EnvanterAdi.[EnvanterAdiID] = Assets.[EnvanterAdiID]) ON Marka.[MarkaID] = Assets.[MarkaID]
WHERE (((Assets.AyniUrunNumarasi) Is Null Or (Assets.AyniUrunNumarasi)="0") AND ((Marka.MarkaKodu) Is Null Or (Marka.MarkaKodu)="0") AND (([Asset Categories].EnvanterSinifiKodu) Is Null Or ([Asset Categories].EnvanterSinifiKodu)="0") AND ((EnvanterAdi.EnvanterAdiKodu) Is Null Or (EnvanterAdi.EnvanterAdiKodu)="0"));
 

Users who are viewing this thread

Back
Top Bottom