A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Programmatically send Email text containing hyperlinks from Access



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 3rd 06, 03:45 PM posted to microsoft.public.outlook.program_vba
momotaro
external usenet poster
 
Posts: 2
Default Programmatically send Email text containing hyperlinks from Access

I would like to send Email test containing hyperlinks programmatically from
Access using a table that contains each mail receipant's information with
some hyperlink fields.
I compose a message body combining the contents of the fields in the table for
each receipant (record). A testing programs worked fine when the contents
only includes "string" data. However, I would ultimately like to contain the
contents of the hyperlinnk fields of the filed. The following codes failed
with Run-Time error '91': Object variable or with variable not set - at the
line for assignment of the content of hyperlink field to hyperlink type
variable. How can I make message body contains both text strings and
hyperlinks?

Private Sub SendEmail()

Dim subjectEmail As String
Dim bodyEmail As String
Dim toEmail As String

Dim db As Database
Dim rst As DAO.Recordset
Dim icount As Integer
Dim lActual As Hyperlink

subjectEmail = "Monthly Resource Management Report(MR2)"
bodyEmail = "Please check the link "

Set db = CurrentDb()
Set rst = db.OpenRecordset("tblSupervisor")

With rst
If .RecordCount 0 Then
icount = .RecordCount
Debug.Print icount ' # of records in tblSupervisor
' move to the first
.MoveFirst
For i = 1 To icount
Debug.Print ![Supervisor]
toEmail = ![Email_Name]
lActual = ![Link_Actual_Collection] ------- error
occurred at this line
bodyEmail = bodyEmail & lActual
Call CreateEmailItem(subjectEmail, _
toEmail, bodyEmail)
End If
.MoveNext
Next i
.Close

End If
End With
End Sub

  #2  
Old May 4th 06, 06:10 AM posted to microsoft.public.outlook.program_vba
Dave Kane [MVP - Outlook]
external usenet poster
 
Posts: 33
Default Programmatically send Email text containing hyperlinks from Access

According to the object browser it looks like an Access Hyperlink is an
object. In that case you would need a Set statement to assign it (Set
lActual = ![Link_Actual_Collection]), which is probably the source of your
error. But that may not be very useful anyway. According to this article
http://www.asp101.com/tips/index.asp?id=100 a hyperlink field is really a
specialized text field that combines the Display Text, Address and
SubAddress separated by # symbols. Outlook won't understand or display a
string like that as a hyperlink without some help. You will need to parse
the string in the hyperlink field and convert it to an HTML hyperlink. Try
this
Dim strLink as String
Dim astrLink() as String
Dim strDisplay as String
Dim strAddress as String

'split the string at the # delimiters and drop in an array
astrLink=Split(![Link_Actual_Collection], "#")
'Display Text may be blank
If Len(astrLink(0))0 Then
strDisplay = astrLink(0)
Else
'use the address as the display
strDisplay = astrLink(1)
End If
'Sub Address may be blank
If Len(astrLink(2))0 Then
strAddress = astrLink(1) & "#" & astrLink(2)
Else
strAddress = astrLink(1)
End If
'construct HTML hyperlink
strLink = "a href='" & strAddress & "'" & strDisplay & "/a"

Append that link to your bodyEmail value. When you create the email in
CreateEmailItem you can assign that string to the HTMLBody property of your
MailItem.


"momotaro" wrote in message
...
I would like to send Email test containing hyperlinks programmatically from
Access using a table that contains each mail receipant's information with
some hyperlink fields.
I compose a message body combining the contents of the fields in the table
for
each receipant (record). A testing programs worked fine when the contents
only includes "string" data. However, I would ultimately like to contain
the
contents of the hyperlinnk fields of the filed. The following codes failed
with Run-Time error '91': Object variable or with variable not set - at
the
line for assignment of the content of hyperlink field to hyperlink type
variable. How can I make message body contains both text strings and
hyperlinks?

Private Sub SendEmail()

Dim subjectEmail As String
Dim bodyEmail As String
Dim toEmail As String

Dim db As Database
Dim rst As DAO.Recordset
Dim icount As Integer
Dim lActual As Hyperlink

subjectEmail = "Monthly Resource Management Report(MR2)"
bodyEmail = "Please check the link "

Set db = CurrentDb()
Set rst = db.OpenRecordset("tblSupervisor")

With rst
If .RecordCount 0 Then
icount = .RecordCount
Debug.Print icount ' # of records in tblSupervisor
' move to the first
.MoveFirst
For i = 1 To icount
Debug.Print ![Supervisor]
toEmail = ![Email_Name]
lActual = ![Link_Actual_Collection] ------- error
occurred at this line
bodyEmail = bodyEmail & lActual
Call CreateEmailItem(subjectEmail, _
toEmail, bodyEmail)
End If
.MoveNext
Next i
.Close

End If
End With
End Sub



  #3  
Old May 4th 06, 08:44 PM posted to microsoft.public.outlook.program_vba
momotaro
external usenet poster
 
Posts: 2
Default Programmatically send Email text containing hyperlinks from Ac



"Dave Kane [MVP - Outlook]" wrote:

Append that link to your bodyEmail value. When you create the email in
CreateEmailItem you can assign that string to the HTMLBody property of your
MailItem.


Thank you very much for your advice. I composed the HTML string containing
message and address and used the HTMLBody property of Mailitem. It solved my
question!
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to programmatically save all email attachments in a folder Brian Beck Outlook and VBA 1 April 20th 06 02:47 PM
VBA Code to put in Access that will send an Email with Attachments [email protected] Outlook and VBA 1 April 9th 06 05:30 PM
How to differ between received and sent email programmatically Darius Add-ins for Outlook 3 April 6th 06 08:06 PM
How to add a bitmap footer to each outgoing email programmatically Herve cadieu Outlook and VBA 3 March 13th 06 05:39 PM
Send Web Page by Email (hyperlinks don't work) John Reames Outlook - General Queries 0 January 13th 06 09:03 PM


All times are GMT +1. The time now is 06:01 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.