Solved

Emailing from VB5

Posted on 2002-04-22
12
160 Views
Last Modified: 2010-05-02
I would like to put an option into my application so the user can email the database to a someone else.

So it would have to open Outlook up and then attach the databse to a new amil message.

Is this possable and if so has any one have some code I can get started with.

Thanks
Steve
0
Comment
Question by:steve_mills
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6961837
0
 

Author Comment

by:steve_mills
ID: 6961853
This is a good link but I am using VB5.0 sorry

Thanks
Steve
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6961856
you have 2 options:

1. since you have all the source code, try opening it into VB5 and compile it.

2. Use the DLL and distribute it with your app (do not forget msvbvm60.dll and maybe other requirements that I could tell you).
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 8

Expert Comment

by:glass_cookie
ID: 6961868
Hi!

Here's a file for you over the net:

View code...
http://www.planetsourcecode.com/vb/scripts/ShowCodeAsText.asp?txtCodeId=5946&lngWId=1
Description: This code will send email through MS Outlook 98, (or the most current version on your computer), using MS Excel 7.0 or higher.

That's it!

glass cookie : )

PS. If you've received an error message saying that 'Retained' is an invalid keyword or something similiar to that, simply open the vbp file in txt format and remove te line:

Retained = 0

That's all : )
0
 

Author Comment

by:steve_mills
ID: 6961874
Can can not open the .vbp files I get an error
Retained is an invalid key.

And I cannot load the dll into my project either.

Thanks
Steve
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6961878
delete the retained line from the VBP file. it is a compilation option in VB6.
0
 

Author Comment

by:steve_mills
ID: 6961922
glass cookie
this code works but I would like it to show the send mail form from outlook so the user can select the recipient of the mail message from the global address book.

Thanks
steve
0
 
LVL 3

Expert Comment

by:n_narayanan
ID: 6962252
Look at this code,

http://www.freevbcode.com/ShowCode.Asp?ID=3886

Cheers

Narayanan
0
 
LVL 3

Expert Comment

by:n_narayanan
ID: 6962255
Or this one will work in VB5 also

http://www.freevbcode.com/ShowCode.Asp?ID=159

Narayanan
0
 
LVL 3

Expert Comment

by:n_narayanan
ID: 6962263
I am appending the above referenced code from freevbcode.com for your quick reference,

====================================================
The owner of the code is Stanley Campbell and not me.
=====================================================

Public Sub SendOutlookMail(Subject As String, Recipient As _
String, Message As String)

On Error GoTo errorHandler
Dim oLapp As Object
Dim oItem As Object

Set oLapp = CreateObject("Outlook.application")
Set oItem = oLapp.createitem(0)
'
With oItem
   .Subject = Subject
   .To = Recipient
   .body = Message
   .Send
End With
'
Set oLapp = Nothing
Set oItem = Nothing
'

Exit Sub

errorHandler:
Set oLapp = Nothing
Set oItem = Nothing
Exit Sub
End Sub
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 6962369
You can use this to create and DISPLAY an Outlook message (this code is in a class for me):

Private mstrAddressTo As String
Private mstrBody As String
Private mstrSubject As String

Public Property Get AddressTo() As String
    AddressTo = mstrAddressTo
End Property
Public Property Let AddressTo(ByVal vdata As String)
    mstrAddressTo = vdata
End Property


Public Property Get Body() As String
    Body = mstrBody
End Property
Public Property Let Body(ByVal vdata As String)
    mstrBody = vdata
End Property


Public Property Get Subject() As String
    Subject = mstrSubject
End Property
Public Property Let Subject(ByVal vdata As String)
    mstrSubject = vdata
End Property

Public Sub SendMailWithOutlook()
Dim objMessage As Object  'Outlook.MailItem
Dim objOutlook As Object  'Outlook.Application

    On Error GoTo ErrHandler
   
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMessage = objOutlook.CreateItem(0)  '(olMailItem)

    With objMessage
        If Len(Trim$(AddressTo)) = 0 Then
            .recipients.Add " "  '"someone@somewhere.com"
        Else
            .recipients.Add AddressTo
        End If
        .Subject = Subject
        .Body = Body
        .Display
    End With
    Set objMessage = Nothing
    Set objOutlook = Nothing
   
    Exit Sub
   
ErrHandler:
    If Err.Number = -2147024894 Then
        MsgBox "An error occured while trying to attach " & Attachments & " to the e-mail!!!" & _
               vbCrLf & vbCrLf & _
               "Error: " & Err.Number & ": " & Err.Description
    Else
        MsgBox "An error occured while trying to prepare an e-mail!!!" & _
               vbCrLf & vbCrLf & _
               "Error: " & Err.Number & ": " & Err.Description
    End If
End Sub
0
 

Author Comment

by:steve_mills
ID: 6964892
I have acheived a good starting piont with this code.
I know see outlook and have been able to attach the required doc., put in a recp name if I want to ect.

Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question