Solved

Emailing from VB5

Posted on 2002-04-22
12
158 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 69

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 69

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
 
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 69

Expert Comment

by:Éric Moreau
ID: 6961878
delete the retained line from the VBP file. it is a compilation option in VB6.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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 69

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now