devpta 0 Newbie Poster

Hello.

I'm using Windows 2000 O/S, VB6 SP6, and Outlook 2002. I'm trying to create a new email from VB6. When outlook is already running, the program works fine, but when it's not, errors come up. I would like to allow the users to preview the email and have them send it by clicking on the send button when it displays. I'm getting an error when it displays, with Outlook not running, and also getting an error when I try to use the GetObject(). Could someone point me in the right direction? Thanks in advance. The coding is as follows:

Public Sub SendMail(p_strTo As String, p_strSub As String, p_strMsg As String)

  Dim objOutlookApp As Outlook.Application
  Dim objMailMessage As Outlook.MailItem
  Dim objAddSig As Outlook.Inspector
  Dim strEmailSignature As String
  Dim strEmailSig1 As String, strEmailSig2 As String
  Dim objNameSpace As NameSpace

  '// - getting Runtime error '429' ActiveX control cannot create object
  '//   error on the following line; hence is commented
  'Set objOutlookApp = GetObject(, "Outlook.Application")

  Set objOutlookApp = CreateObject("Outlook.Application")
  Set objMailMessage = objOutlookApp.CreateItem(olMailItem)
  Set objAddSig = objMailMessage.GetInspector
  Set objNameSpace = objOutlookApp.GetNamespace("MAPI")
  objNameSpace.Logon
  
  '// - get the outlook email signature
  strEmailSignature = objAddSig.CurrentItem.Body
  '// - break up the email signature to get rid of the HYPERLINK word
  '//   and the email address in quotes
  strEmailSig1 = Mid(strEmailSignature, 1, InStr(1, strEmailSignature, "HYPERLINK", vbTextCompare) - 1)
  strEmailSig2 = Mid(strEmailSignature, InStrRev(strEmailSignature, Chr(34)) + 1)
  '// - combine
  strEmailSignature = strEmailSig1 & strEmailSig2
  
  With objMailMessage
[INDENT]    .To = p_strTo
   .Subject = p_strSub
    .Body = p_strMsg & vbCrLf & strEmailSignature
    '// - getting Method 'Display' of object '_MailItem' failed error
    '//   on the following line if Outlook is not running
    .Display[/INDENT]
  End With
    
  objNameSpace.Logoff
  
  objOutlookApp.Quit
   
  Set objOutlookApp = Nothing
  Set objMailMessage = Nothing
  Set objNameSpace = Nothing
     
End Sub