Sending emails using control as records source (1 Viewer)

JPR

Registered User.
Local time
Today, 10:11
Joined
Jan 23, 2009
Messages
192
Hello,

I have f form used to export data to a MS Word template which is then attached to a new Outlookl session.

Since the recipient email address can change, I would like to choose the email address directly from a combo available on my form , which lists all the recipients.

The part of the code I have to select the recipient is the following:

Code:
' correct code
.TO = "jpr@gmail.com"

' wrong code
.To = Me.Combo

I was wandering if this could be done. Thank you
 

JPR

Registered User.
Local time
Today, 10:11
Joined
Jan 23, 2009
Messages
192
Great. Working perfectly!!! Thank you
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:11
Joined
May 7, 2009
Messages
19,169
you can also use Multi-select Listbox so you can
have multiple Recipients.
 

JPR

Registered User.
Local time
Today, 10:11
Joined
Jan 23, 2009
Messages
192
Perfect. Will try it.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:11
Joined
Jul 9, 2003
Messages
16,244
That's great!

The reason I was sceptical was because by default MS Access should return the value, so you don't need "Value" as it is the default.

However some pieces of code DO NOT grab the value, but assume that you are referring to the control "Object" itself.

I have seen this referencing the Object instead of value, in converted macros and in a couple of other places.

I have yet to work out the rules governing how the code makes the choice of accessing the object or alternatively it's value.

I am collecting instances of this overriding of choosing the default value and accessing the actual control object on my website here:-


Will add this new information to my website!
 
Last edited:

Minty

AWF VIP
Local time
Today, 17:11
Joined
Jul 26, 2013
Messages
10,355
It's often to do with the scope and where the object is referred to - I have seen lots of Outlook code fail trying to reference objects directly in a With block;

This will work

Code:
    Variable_To = Me.Combo1
    
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next
    With OutMail
        .BodyFormat = 2 'olFormatHTML
        .Display
    End With
    
    signature = OutMail.HTMLBody
        
    With OutMail
    
        .To = Variable_To
        .CC = ""
        .BCC = ""
        .Subject = Variable_Subject
        
        etc etc

Whereas this won't

Code:
With OutMail
    
        .To = Me.Combo1
I've never figured out the actual reason, but it has to be the fact that you are already "within" the Outlook object reference at the time.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:11
Joined
Sep 21, 2011
Messages
14,044
That's great!

The reason I was sceptical was because by default MS Access should return the value, so you don't need "Value" as it is the default.

However some pieces of code DO NOT grab the value, but assume that you are referring to the control "Object" itself.

I have seen this referencing the Object instead of value, in converted macros and in a couple of other places.

I have yet to work out the rules governing how the code makes the choice of accessing the object or alternatively it's value.

I am collecting instances of this overriding of choosing the default value and accessing the actual control object on my website here:-


Will add this new information to my website!
Tempvars are like that, I have found you need the .Value ?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:11
Joined
Jul 9, 2003
Messages
16,244
Tempvars are like that, I have found you need the .Value ?

Yes, that's it, I remember now, the macro I was converting actually contained
a TempVar I did a blog about it somewhere!
 

Users who are viewing this thread

Top Bottom