Solved

Emailing from VB5

Posted on 2002-04-22
12
159 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

919 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

14 Experts available now in Live!

Get 1:1 Help Now