Results 1 to 16 of 16

Thread: vb6 access200- data to a email template

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    vb6 access200- data to a email template

    Hello everyone, thank you for all your help on my project i am trying to do.

    I'm not sure if this is possiable or not, but.
    I wanted to take a customers information that i pulled up in my database, throught a gui interface made in vb. And i wanted to make a "email" button, so that it would take certain values from the fields that i pulled up, and insert them into places in the email document.

    Such as, when i hit the "email" button, i have a template saved on my server or somewhere, and it will take the first name and last name, and insert them into the outlook message template so that i dont have to type them in there?

    Is something like this even possiable?

    Thanks again
    Joe

  2. #2
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: vb6 access2000 - data to a email template

    Sure it's possible.
    There are a few limitations if you want it to be a simple process, but yes, in principle it is possible.

    It sounds like the easiest way would be to reference the Outlook object library in your project and create a message from there - either hard-coding the content or storing it in a text/xml/db file that you read in and 'fill out' each time.
    [This restricts you if you ever want to distribute your application, as it relies on the Outlook object model, but creating SMTP clients etc. in VB6 involves a nasty trip into Windows APIs...]

    Hope this starts you off.

  3. #3

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: vb6 access200- data to a email template

    Yeah, Im looking for the easiest way to do it.
    how would I even start a button like this?
    Just curious.

    Thanks
    Joe

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: vb6 access200- data to a email template

    keep in mind that outlook throws up a warning for each record that you want to email, and won't let you approve it for 5 seconds. i automated a mailmerge, and couldn't get around it. I recommend the vbsendmail approach. Serch for it.
    If I didn't have to do everything that the MailMerge did, I would have, also, but smtp doesn't work with MM.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: vb6 access200- data to a email template

    Quote Originally Posted by joefox
    Yeah, Im looking for the easiest way to do it.
    how would I even start a button like this?
    Just curious.

    Thanks
    Joe
    like previously posted, we need to know what you want to use to do the emailing (Outlook vbSendMail, SMTP,etc.).
    If the Outlook Security Popup warning message is not a problem, then Outlook will be the easiest.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: vb6 access200- data to a email template

    Actually it sounds to me like a formatted "mailto" would be appropriate in this situation, it depends if the email should come up on screen & be editable (the "send" must be done manually if so).

    If that is what you want, this code will work nicely: (otherwise, RobDog888 is the man in the know )
    VB Code:
    1. 'This code can be pasted as-is into a form (only usable in that form),
    2.             'or a module (can be used anywhere in the project)
    3. 'in "general declarations":
    4. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    5. (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    6. ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    7. Const SW_SHOWNORMAL = 1
    8.  
    9. 'the sub:
    10. Sub My_Mailto(pr_Recipients_s As String, _
    11.               Optional pr_Subject_s As String = "", _
    12.               Optional pr_Body_s As String = "", _
    13.               Optional pr_CC_s As String = "", _
    14.               Optional pr_BCC_s As String = "")
    15. '---------------------------------------------------------------------------------------
    16. ' Purpose   :  Create an email (not sent automatically)
    17. ' Returns   :  (none)
    18. ' Parameters:  (various email fields)
    19. ' Author    :  Si_the_geek (vbForums.com)
    20. ' Date      :  Fri 14 Jan 2005
    21. '---------------------------------------------------------------------------------------
    22.  
    23. Dim vl_Execute_s As String      'Format the parameters
    24.   vl_Execute_s = "mailto:" & pr_Recipients_s
    25.  
    26.   If (pr_Subject_s <> "") Then
    27.     vl_Execute_s = vl_Execute_s & "&subject=" & pr_Subject_s
    28.   End If
    29.   If (pr_CC_s <> "") Then
    30.     vl_Execute_s = vl_Execute_s & "&cc=" & pr_CC_s
    31.   End If
    32.   If (pr_BCC_s <> "") Then
    33.     vl_Execute_s = vl_Execute_s & "&bcc=" & pr_BCC_s
    34.   End If
    35.   If (pr_Body_s <> "") Then
    36.     vl_Execute_s = vl_Execute_s & "&body=" & pr_Body_s
    37.   End If
    38.  
    39.                                 'Convert CR's to HTML CR's
    40.     '(note - this works well for Outlook, not tested on other clients)
    41.   vl_Execute_s = Replace(vl_Execute_s, vbCr, "%0A")
    42.  
    43.                                 'Create the mail
    44.   ShellExecute 0, vbNullString, vl_Execute_s, vbNullString, "C:\", SW_SHOWNORMAL
    45.  
    46. End Sub
    VB Code:
    1. 'example usage:
    2. Dim sBodyText as String
    3. sBodyText = "body text here" & vbcr & "testing testing"
    4. Call My_Mailto ("[email protected]","subject here",sBodyText)

    In this particular case you can load the "template" into the sBodyText variable, and put the specific name data in before the call to the sub.

    I would personally store the templates in the database, and use markers in the templates (such as {#1#}) so that you can replace them easily in your code, like this:
    VB Code:
    1. sBodyText = "body text here" & vbcr & "testing {#1#} testing {#2#}*"
    2.  
    3. sBodyText = replace(sBodyText, "*#1#*", txtFirstName.text)
    4. sBodyText = replace(sBodyText, "*#1#*", txtSurname.text)
    5. Call My_Mailto (....

  7. #7

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: vb6 access200- data to a email template

    Hello, i would be using using Microsoft Outlook 2002.

  8. #8

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: vb6 access200- data to a email template

    Hello,
    Thank you for the code, But i dont see where it put in the values that are displayed in my visual basic program.
    I wanted to say search from someone in my database, it pulls up there info, then i hit the "email" button, and it basiclly, takes the fname lname serialnumber fields, and puts them into the email template, that way all i have to do is look it over, and hit send.. here is what i have so far with the code..

    Thanks for the help everyone!

    VB Code:
    1. 'the sub:
    2. Sub My_Mailto(pr_Recipients_s As String, _
    3.               Optional pr_Subject_s As String = "", _
    4.               Optional pr_Body_s As String = "", _
    5.               Optional pr_CC_s As String = "", _
    6.               Optional pr_BCC_s As String = "")
    7.  
    8. Dim vl_Execute_s As String
    9.   vl_Execute_s = "mailto:" & pr_Recipients_s
    10.  
    11.   If (pr_Subject_s <> "") Then
    12.     vl_Execute_s = vl_Execute_s & "&subject=" & pr_Subject_s
    13.   End If
    14.   If (pr_CC_s <> "") Then
    15.     vl_Execute_s = vl_Execute_s & "&cc=" & pr_CC_s
    16.   End If
    17.   If (pr_BCC_s <> "") Then
    18.     vl_Execute_s = vl_Execute_s & "&bcc=" & pr_BCC_s
    19.   End If
    20.   If (pr_Body_s <> "") Then
    21.     vl_Execute_s = vl_Execute_s & "&body=" & pr_Body_s
    22.   End If
    23.  
    24. vl_Execute_s = Replace(vl_Execute_s, vbCr, "%0A")
    25. 'Create the mail
    26. ShellExecute 0, vbNullString, vl_Execute_s, vbNullString, "C:\", SW_SHOWNORMAL
    27.  
    28. ' Example Usage
    29. Dim sBodyText As String
    30. sBodyText = "Hello," & vbCr & "Thank you for your time and patience.." & vbCr & "Your new serial number is: "
    31. Call My_Mailto("[email protected]", "New Serial Number", sBodyText)
    32.  
    33. sBodyText = "body text here" & vbCr & "testing {#1#} testing {#2#}*"
    34.  
    35. sBodyText = Replace(sBodyText, "*#1#*", txtFirstName.Text)
    36. sBodyText = Replace(sBodyText, "*#1#*", txtSurname.Text)

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: vb6 access200- data to a email template

    Once you have the "My_MailTo" sub in your project, you just need something like this:
    VB Code:
    1. Dim sBodyText As String
    2. sBodyText = "Hello " & rs("fname") & " " & rs("lname") & "," & vbCr _
    3.           & "Thank you for your time and patience.." & vbCr _
    4.           & "Your new serial number is: " & rs("serialnumber")
    5. Call My_Mailto("[email protected]", "New Serial Number", sBodyText)

    I was assuming before that you wanted multiple email templates (hence the Replace business)

  10. #10

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: vb6 access200- data to a email template

    Hello SI..
    Dang you guys are good..

    Ok it worked perfectly..
    My only question is...
    I needed the mailto, to be the customer email address, not my email.
    Same

    here is what i have

    VB Code:
    1. Private Sub EmailtheCustomer_Click()
    2. Dim sBodyText As String
    3. sBodyText = "Hello " & rs("fname") & " " & rs("lname") & "," & vbCr _
    4.           & "Thank you for your time and patience.." & vbCr _
    5.           & "Your new serial number is: " & rs("serialnumbersoftware")
    6. Call My_Mailto("[email protected]", "New Serial Number", sBodyText)
    7.  
    8. End Sub

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: vb6 access200- data to a email template

    assuming you have a database field called email:

    Call My_Mailto(rs("email"), "New Serial Number", sBodyText)

  12. #12

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: vb6 access200- data to a email template

    wow..again works like a charm..

    Now if i wanted to make another button, that does the same function, but is a different template, i would just make a different button, and change the values in that button right?

  13. #13

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: vb6 access200- data to a email template

    Ah i figured it out, i just made a new button, and changed the template in it.

    Thanks again!
    Joe

  14. #14

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: vb6 access200- data to a email template

    Oh wait, just another quick question, what if i wanted to have text in my subject and a value from my database, such as:

    Subject: New Serial Number for (value in database)

    Thanks
    Joe

  15. #15
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: vb6 access2000 - data to a email template

    Same again really:
    VB Code:
    1. Dim strSubject as string
    2. strSubject = "New Serial Number for " & rs("value in database")
    3. Call My_Mailto(rs("email"), strSubject , sBodyText)

  16. #16

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: vb6 access200- data to a email template

    GOT IT!
    Perfect! Thanks Everyone!
    :mike:

Posting Permissions

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



Click Here to Expand Forum to Full Width