|
-
Feb 24th, 2005, 05:32 PM
#1
Thread Starter
Frenzied Member
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
-
Feb 24th, 2005, 05:55 PM
#2
Frenzied Member
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.
-
Feb 24th, 2005, 06:08 PM
#3
Thread Starter
Frenzied Member
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
-
Feb 24th, 2005, 08:16 PM
#4
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.
-
Feb 24th, 2005, 08:22 PM
#5
Re: vb6 access200- data to a email template
 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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 25th, 2005, 04:45 AM
#6
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:
'This code can be pasted as-is into a form (only usable in that form),
'or a module (can be used anywhere in the project)
'in "general declarations":
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
'the sub:
Sub My_Mailto(pr_Recipients_s As String, _
Optional pr_Subject_s As String = "", _
Optional pr_Body_s As String = "", _
Optional pr_CC_s As String = "", _
Optional pr_BCC_s As String = "")
'---------------------------------------------------------------------------------------
' Purpose : Create an email (not sent automatically)
' Returns : (none)
' Parameters: (various email fields)
' Author : Si_the_geek (vbForums.com)
' Date : Fri 14 Jan 2005
'---------------------------------------------------------------------------------------
Dim vl_Execute_s As String 'Format the parameters
vl_Execute_s = "mailto:" & pr_Recipients_s
If (pr_Subject_s <> "") Then
vl_Execute_s = vl_Execute_s & "&subject=" & pr_Subject_s
End If
If (pr_CC_s <> "") Then
vl_Execute_s = vl_Execute_s & "&cc=" & pr_CC_s
End If
If (pr_BCC_s <> "") Then
vl_Execute_s = vl_Execute_s & "&bcc=" & pr_BCC_s
End If
If (pr_Body_s <> "") Then
vl_Execute_s = vl_Execute_s & "&body=" & pr_Body_s
End If
'Convert CR's to HTML CR's
'(note - this works well for Outlook, not tested on other clients)
vl_Execute_s = Replace(vl_Execute_s, vbCr, "%0A")
'Create the mail
ShellExecute 0, vbNullString, vl_Execute_s, vbNullString, "C:\", SW_SHOWNORMAL
End Sub
VB Code:
'example usage:
Dim sBodyText as String
sBodyText = "body text here" & vbcr & "testing testing"
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:
sBodyText = "body text here" & vbcr & "testing {#1#} testing {#2#}*"
sBodyText = replace(sBodyText, "*#1#*", txtFirstName.text)
sBodyText = replace(sBodyText, "*#1#*", txtSurname.text)
Call My_Mailto (....
-
Feb 25th, 2005, 10:32 AM
#7
Thread Starter
Frenzied Member
Re: vb6 access200- data to a email template
Hello, i would be using using Microsoft Outlook 2002.
-
Feb 25th, 2005, 10:39 AM
#8
Thread Starter
Frenzied Member
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:
'the sub:
Sub My_Mailto(pr_Recipients_s As String, _
Optional pr_Subject_s As String = "", _
Optional pr_Body_s As String = "", _
Optional pr_CC_s As String = "", _
Optional pr_BCC_s As String = "")
Dim vl_Execute_s As String
vl_Execute_s = "mailto:" & pr_Recipients_s
If (pr_Subject_s <> "") Then
vl_Execute_s = vl_Execute_s & "&subject=" & pr_Subject_s
End If
If (pr_CC_s <> "") Then
vl_Execute_s = vl_Execute_s & "&cc=" & pr_CC_s
End If
If (pr_BCC_s <> "") Then
vl_Execute_s = vl_Execute_s & "&bcc=" & pr_BCC_s
End If
If (pr_Body_s <> "") Then
vl_Execute_s = vl_Execute_s & "&body=" & pr_Body_s
End If
vl_Execute_s = Replace(vl_Execute_s, vbCr, "%0A")
'Create the mail
ShellExecute 0, vbNullString, vl_Execute_s, vbNullString, "C:\", SW_SHOWNORMAL
' Example Usage
Dim sBodyText As String
sBodyText = "Hello," & vbCr & "Thank you for your time and patience.." & vbCr & "Your new serial number is: "
sBodyText = "body text here" & vbCr & "testing {#1#} testing {#2#}*"
sBodyText = Replace(sBodyText, "*#1#*", txtFirstName.Text)
sBodyText = Replace(sBodyText, "*#1#*", txtSurname.Text)
-
Feb 25th, 2005, 01:17 PM
#9
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:
Dim sBodyText As String
sBodyText = "Hello " & rs("fname") & " " & rs("lname") & "," & vbCr _
& "Thank you for your time and patience.." & vbCr _
& "Your new serial number is: " & rs("serialnumber")
I was assuming before that you wanted multiple email templates (hence the Replace business)
-
Feb 25th, 2005, 01:56 PM
#10
Thread Starter
Frenzied Member
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:
Private Sub EmailtheCustomer_Click()
Dim sBodyText As String
sBodyText = "Hello " & rs("fname") & " " & rs("lname") & "," & vbCr _
& "Thank you for your time and patience.." & vbCr _
& "Your new serial number is: " & rs("serialnumbersoftware")
End Sub
-
Feb 25th, 2005, 02:11 PM
#11
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)
-
Feb 25th, 2005, 02:26 PM
#12
Thread Starter
Frenzied Member
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?
-
Feb 25th, 2005, 02:43 PM
#13
Thread Starter
Frenzied Member
-
Feb 25th, 2005, 02:52 PM
#14
Thread Starter
Frenzied Member
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
-
Feb 25th, 2005, 03:13 PM
#15
Frenzied Member
Re: vb6 access2000 - data to a email template
Same again really:
VB Code:
Dim strSubject as string
strSubject = "New Serial Number for " & rs("value in database")
Call My_Mailto(rs("email"), strSubject , sBodyText)
-
Feb 25th, 2005, 03:46 PM
#16
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|