Results 1 to 11 of 11
  1. #1
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Generating an Email from a VB form label (VB6)

    When I click on Label1 in a VB Form, I want it to open the users email program and start an email to me. The address, subject and message should be filled in, using data from the Form. or variables that I provide.

    Any clues how to code this?
    Thanks

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Generating an Email from a VB form label (VB6)

    Can you count on the person having Outlook, or do you need something that will work with any mailer?

  3. #3
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Generating an Email from a VB form label (VB6)

    This needs to work from any mailer.

    I have done this from an xl spreadsheet but I think its a little different in VB

  4. #4
    Star Lounger
    Join Date
    Jan 2001
    Location
    L.A., California
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Generating an Email from a VB form label (VB6)

    There are a couple of ways that I know of to do this. Microsoft has MAPI controls which can be used to create an e-mail message using your MAPI-compliant mail program. You can start an e-mail message, even have an attachment. You have to search the help for "MAPI controls" for useage.

    If you don't need a visible e-mail client interface, and only want to send the message, there's an excellent freeware program available, called BLAT. It's a dos command line utility, but can be called from VB. You need to have access to an SMTP mail server. Once installed, you can send a message with attachments if desired, with no further user interaction. Search for "blat" on google.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Generating an Email from a VB form label (VB6)

    How did you do it in Excel, with a mailto: link? Probably your method can be adapted, unless it uses a built-in function in Excel.

  6. #6
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Generating an Email from a VB form label (VB6)

    I went back and found the spreadsheet where I did this before. It was with a mailto: string. I found now that it works if I am using AOL as the mailing service but I am now using Outlook Express and think that this would be most likely the case or at least Outlook for this new project.

    Here is the gist of the code:

    dim BODY, MailtoString as String
    dim SUBJ as Range

    BODY = "This*is*my*text:%OD%OA%OD%OA"

    'when I previewed this posting I found that the symbol for the space between the words was removed.
    'I have indicated it with an asterisk. In code it is a combination of % percent sign, 2, and zero - all concatenated - no commas

    BODY = BODY & Range("A1") & "%OD%OA"
    'add more text
    set SUBJ = Range("A2")
    MailtoString = "mailto: Webmaster@domain.com?subject=" & SUBJ & "&body=" & BODY

    In aol it worked fine. With Outlook Express the * (characters for Space) and %OD%OA (Carriage return/line feed) were not interpreted. I'm just thinking as I write: maybe I should put these characters outside of the quotation marks. Either that, or replace them with the characters that OE will recognize.

    ......

    Well I tried putting them outside the quote but this didn't work. ?????

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Generating an Email from a VB form label (VB6)

    It works with Outlook; I didn't test with Outlook Express. Try this sample:

    <pre>Private Sub Label1_Click()
    ActiveDocument.FollowHyperlink "mailtoldbuddy@testdomain.xx?" & _
    "subject=Why haven't I heard from you" & _
    "&body=Hey, pal. It's about time you call me." & "% 0A% 0D" & _
    "I'll buy you a beer. See ya. -Me"
    Me.Hide
    End Sub</pre>

    Note that those hex characters are % zero D and % zero A without spaces, and just use plain spaces rather than % 2 0.

  8. #8
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Generating an Email from a VB form label (VB6)

    Jefferson,

    Thanks for the help. I still need to adapt a little to make it work strickly from within a VB Form (no Word or Excel docs involved) - just VB and a mailto string.

    I tried substituting "Labelx" for "ActiveDocument" in your code but this failed.

    VB Help doesn't show a FollowHyperLink property but it does have a HyperLink property of the UserDocument and the UserControl objects. I'm not sure how to make the syntax work for these.


    Thanks
    Paul

  9. #9
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Generating an Email from a VB form label (VB6)

    Perhaps this will clarify a little.

    The following code works to send an email message while I am in Excel. I'd like to do the same from within a VB Form. Where I'm having difficulty is: in Excel I have a cell (range("OrderEmail") which is already a hyperlink to my email address. In the following code, I select it, then add a new mailto string, then do the "FollowHyperLink" command. How can I adapt this for use in a VB form? I can easily change the Range references to Label.Captions or Textbox.Text to get the message content, but I haven't figured out the link part yet.
    Thanks


    Sub EMAIL_PO()

    Dim MyOrder, MyAddress As String


    ''This range has the Body of the message I want emailed
    'Note: I added the word "linefeed" as the formun deletes the characters "vbcrlf"

    msg = "TO: SFP.com" & linefeed
    msg = msg & "DATE: " & Date & linefeed
    msg = msg & "Please process my order as follows. " & linefeed
    msg = msg & Range("A1") & " $" & Range("B1") & linefeed
    msg = msg & Range("A2") & Range("B2") & linefeed
    msg = msg & "CATEGORIES: " & linefeed
    msg = msg & "Revenue: " & Range("C1") & linefeed
    'etc, etc

    ''create the mailto string

    MyOrder = Range("D2")
    MyAddress = "mailto:Webmaster@SFP.com?subject=" & MyOrder & "&body=" & msg

    'go to the email link
    Sheets("OrderForm").Activate
    Range("OrderEmail").Select

    'create a new mailto for this link
    With Worksheets("OrderForm")
    .Hyperlinks.Add Anchor:=.Range("OrderEmail"), _
    Address:=myAddress
    End With

    'send the email
    Selection.Hyperlinks(1).Follow NewWindow:=True, AddHistory:=True

    'go back to worksheet
    Range("A1").Select



    End Sub

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Generating an Email from a VB form label (VB6)

    Whoops, I don't know where I got the idea that you would have Word as part of your application.

    Microsoft must have documented a way to send a generic "make a new mail message" message to the OS. Many applications do it, it's just a matter of finding it. Off the top of my head, I don't know what it is. You might check MSDN and/or Visual Basic sites for more hints if none are forthcoming here.

  11. #11
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Generating an Email from a VB form label (VB6)

    Jefferson

    Thanks for the help. I finally solved it. After changing the range references in my Excel code to label.captions or textbox.text, I ran the sub with a debug.print command to verify that the mailto string was working....no problem. Then it remained to find a way to turn a VB object (label, textbox, or image, etc) into a hyperlink. I did this with a shell execute function which had worked for me before, using a Label Tag to store the link. I then subtituted my email address for the web address in the Tag. Worked like a charm.... at least on my system. Yet to test this beyond.

Posting Permissions

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