Results 1 to 3 of 3

Thread: Outlook has to be running to send mail.

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    flipside of MI
    Posts
    3

    Angry Outlook has to be running to send mail. HELP!!!

    Im trying to send an email automatically with the push of a button. The only problem is that Outlook has to be running in order for the program to work. If outlook is not running, I get an error message (see mvberror.jpg below).

    My code is;

    Dim response
    response = MsgBox("Do you want to send a message to Bev telling her you made a copy of " & lstfiles.FileName, vbYesNo, "STOP")
    If response = vbYes Then 'User chose yes.


    Dim objOutlook As New Outlook.Application
    Dim ObjOutlookMsg As Outlook.MailItem
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    With objOutlookMsg
    .To = "email address"
    .Subject = "test"
    .Body = "Bev, " & vbNewLine
    .Body = .Body & "I made a copy of drawing number: ** " & lstfiles.FileName
    .Body = .Body & " **, from the Bravo folder. " & vbNewLine & vbNewLine
    .Body = .Body & "Thanks"
    .Send
    End With

    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
    End If


    When I press debug on the error, it returns me to

    "Set objOutlookMsg = objOutlook.CreateItem(olMailItem)"

    I dont want to have Outlook running in order to send the file. If anyone can help I would truely appreciate it.

    Thanks in advance,
    el guapo
    Attached Images Attached Images  
    Last edited by el guapo; May 18th, 2001 at 09:26 AM.
    "The cheese is old and moldy, where's the bathroom?"

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Location
    Lincolnshire, UK
    Posts
    111
    Try this style of code, I know this works 'cos we're using it at the moment (ignore getcentrecode and getbatchnumber). This still will not send the email automatically, but this might just be because we're not connected to the web at the time.

    One thing to look out for though, the Outlook reference you use in VB MUST be the same type and version as the client machines (i.e. Outlook 2000 references and Outlook 97 clients will not work, also Outlook Express will not work with anything)

    Hope this helps

    Chris


    Dim OutLookApp As New Outlook.Application
    Dim OutLookEmail As Outlook.MailItem

    Set OutLookEmail = OutLookApp.CreateItem(olMailItem)
    Dim Counter As Long
    Dim Total As Long

    cmdSendEmail.Enabled = False
    If Trim(txtEmail.Text) <> "" Then
    If Dir("c:\temp\C" & GetCentreCode & "B" & GetBatchNumber & ".mdb") <> "" Then
    OutLookEmail.To = txtEmail.Text
    OutLookEmail.Subject = "EMAIL INVOICING"
    OutLookEmail.Attachments.Add "C:\temp\C" & GetCentreCode & "B" & GetBatchNumber & ".mdb"
    OutLookEmail.Send
    End If
    End If
    OutLookApp.Quit
    cmdSendEmail.Enabled = True
    Call MsgBox("Message sent!", vbInformation)

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    flipside of MI
    Posts
    3
    It is still returning an error when I dont have outlook running. When I debug, it goes to the same spot;(Set OutLookEmail = OutLookApp.CreateItem(olMailItem)). My references are correct, so....

    Thanks for the reply though...

    -el guapo
    "The cheese is old and moldy, where's the bathroom?"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width