email Problems

S

Simon

I have the following email code

DoCmd.SendObject acSendNoObject, , , Me.EmailAddress, , , DLookup
("Subject", "tblEmailTemplates", EmailID = 1), "Test
testetsfgdsffdsfdsfdsfdsfdfdfsdfds", fales, ""

The subject of the email i would like it to look it upo from
tblEmailTemplates where EmailID =1.

This code does not work can some one help me in right direction, new
to coding
 
C

Clifford Bass

Hi Simon,

Your criteria needs to be text also ("EmailID = 1" with the quotes).
And you need to correct fales to False.

Clifford Bass
 
A

Arvin Meyer [MVP]

I see 2 things:

First you need to do the DLookup before running the SendObject code:

Dim x
x = DLookup("Subject", "tblEmailTemplates", EmailID = 1)

Second, False is spelled False, not fales.
 
C

Clifford Bass

Hi Arvin,

Arvin Meyer said:
First you need to do the DLookup before running the SendObject code:

Are you sure? It works directly within the SendObject method for me.

Clifford Bass
 
C

Clifford Bass

Hi Arvin,

I agree that one should always initialize variables; too many years as
a c/c++ programmer.

However in terms of calling the SendObject method I do not think that
what you write is the case. When a function/method with parameters is
called, the parameters are evaluated before the function is ever called. So
when "DoCmd.SendObject acSendNoObject, , , Me.EmailAddress, , , DLookup(...."
is used, the DLookup is recognized as a function and is evaluated first.
Then it's return value is used when the SendObject method is actually
invoked. It is functionally equivalent to doing the DLookup separately,
storing it into a variable and then passing the variable into SendObject.
One is implicit and the other is explicit.

This can be demonstrated by the following:

Public Sub Sub1()

Dim strResult As String

MsgBox Fn1(Fn2("Some text."))

strResult = Fn2("Some other text.")
MsgBox Fn1(strResult)

End Sub

Public Function Fn1(strIn As String) As String

MsgBox "Entered Fn1"
Fn1 = strIn

End Function

Public Function Fn2(strIn As String) As String

MsgBox "Entered Fn2"
Fn2 = strIn

End Function

The results in order are:

Entered Fn2
Entered Fn1
Some text.
Entered Fn2
Entered Fn1
Some other text.

Sincerely,

Clifford Bass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top