I will remember copy-and-paste next time, if any.
In the immediate window shows [Kunde Nr] = Jane
And this is the right name from the record, I wil send mail to.
Douglas J. Steele skrev:
It's generally a good idea to copy-and-paste, rather than retyping...
Okay, perhaps stWho doesn't contain what you think it does.
Add a Debug statement in your code:
stWhere = "[Kunde Nr] = " & stWho
Debug.Print stWhere
varTo = DLookup("[Mail]", "[Kunde]", stWhere)
Once you've invoked the code, go to the Immediate window (Ctrl-G) and
see
what it's printed there.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Yes and it still "[Kunde Nr] =". I just forget to change it here,
(done
now). I don't make it any easyer, I guess. Sorry Douglas
Douglas J. Steele skrev:
You said you used the following in the Immediate window:
?DLookup("[Mail]", "[Kunde]", "[Kunde Nr] =5")
However, your code is:
stWhere = "Kunde_Nr = " & stWho
Change that to:
stWhere = "[Kunde Nr] = " & stWho
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Ahhh sorry.
I guess this is what you mean...
Private Sub Send_Rapport_Click()
'On Error GoTo Err_Send_Rapport_Click
Dim stDocName As String
Dim stWhere As String
Dim varTo As Variant
Dim stWho As String
stWho = Me.Fornavn
stWhere = "[Kunde Nr] = " & stWho
'-- Looks up email address from Kunde
varTo = DLookup("[Mail]", "[Kunde]", stWhere) -> this line
is
markt
stDocName = "Detalje Rapport"
'Write the e-mail content for sending to assignee
DoCmd.SendObject , acFormatHTML, varTo, , , acReport,
stDocName,
,
-1
Exit_Send_Rapport_Click:
Exit Sub
'Err_Send_Rapport_Click:
' MsgBox Err.Description
' Resume Exit_Send_Rapport_Click
End Sub
Douglas J. Steele skrev:
This whole thread started because you had code in
Send_Rapport_Click
that
was raising an error.
Since then, you've (presumably) made changes to that code, based
on
our
discussion. What's the code now (and what line raises the
error)?
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Sorry Douglas!
I don't know what you mean with, "what's the actual code I've
using
now that's failing".
Douglas J. Steele skrev:
That means that DLookup is okay with the names you're using,
so
as
long
as
they're identical in your code, it should work.
What's the actual code you've using now that's failing?
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
I have try 2 [Kunde Nr]= 4 and 5
The message underneath ?DLookup("[Mail]", "[Kunde]",
"[Kunde
Nr]
=5")
is the email address from the db record. This is correct.
Does the above make any sence to you?
Douglas J. Steele skrev:
Type the line, then hit Enter. The result should appear
underneath
what
you've typed (or else an error message will pop up)
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
varTo = DLookup("[Mail]", "[Kunde]", stWhere) didn't do
it.
I put the line ?DLookup("[Mail]", "[Kunde]", "[Kunde Nr]
=145")
in
the
Immediate window, but how do I run it from there? The
only
thing
I
can
run is macro, for what I can see.
Douglas J. Steele skrev:
See whether putting square brackets around the names of
the
fields
and
table
helps:
DLookup("[Mail]", "[Kunde]", stWhere)
If not, go to the Immediate window (Ctrl-G) and try
running
the
DLookup
there. You'll need to precede the call with a question
mark:
?DLookup("[Mail]", "[Kunde]", "[Kunde Nr] = 5")
(or whatever value you're currently trying to use for
Kunde
Nr)
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Kunde Nr was numeric and I change the line, but it
didn't
help.
I allso change (Email) to (Mail). Same error...
Here is my table var:
It's in danish, therefore the translation (text) etc.
Tablename = Kunde
Kunde Nr - Tal (Numeric) =Key
Fornavn - Tekst (Text)
Mail - Tekst (Text)
...and some others...
The above is what I use. I try to activate the send
mail
from
"Kunde -
formular". I just can't see where I mistype. Maby
it's
simple,
but
not
for me.
Hope you don't give up on me. But if you do, thanks
for
trying!
Douglas J. Steele skrev:
You're positive you haven't mistyped the name of the
table
(Kunde)
or
the
name of either of the fields (EMail and Kunde Nr)?
Also, what you've got assumes that Kunde Nr is a
text
field.
If
it's
actually numeric, use
stWhere = "[Kunde Nr] = " & stWho
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Hey Douglas!
I'm emty, blank, run out of tears...
I change the line, but the message, "error 2001",
are
still
showing.
Allso [Kunde].[Kunde Nr] did not helt.
Would it helt if you can see the table?
Any other suggestion?
Douglas J. Steele skrev:
That very misleading error message can occur when
you've
made
a
mistake
typing the name of the table or field in DLookup
functions.
In
your
case,
your reference to the field in the Where clause
is
incorrect.
Try
changing
stWhere = "[Kunde.Kunde Nr] = " & "'" & stWho &
"'"
to
stWhere = "[Kunde Nr] = " & "'" & stWho & "'"
(Since you can only have a single domain in
DLookup,
there's
no
need
to
qualify the field. When you do need to refer to
both
the
table
and
field,
such as in an SQL statement, it would be
[Kunde].[Kunde
Nr])
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Hey There!
Is there anyboddy who can help me?
I try to send a mail via Access. This is my
code:
-------------------------------------------------
Private Sub Send_Rapport_Click()
On Error GoTo Err_Send_Rapport_Click
Dim stDocName As String
Dim stWhere As String
Dim varTo As Variant
Dim stWho As String
stWho = Me.Fornavn
stWhere = "[Kunde.Kunde Nr] = " & "'" &
stWho &
"'"
'-- Looks up email address from TblUsers
varTo = DLookup("EMail", "Kunde", stWhere)
'--
this
line
is
markt
stDocName = "Detalje Rapport"
'Write the e-mail content for sending to
assignee
DoCmd.SendObject , acFormatHTML, varTo, , ,
acReport,
stDocName,
,
-1
Exit_Send_Rapport_Click:
Exit Sub
Err_Send_Rapport_Click:
MsgBox Err.Description
Resume Exit_Send_Rapport_Click
End Sub
---------------------------------------
I just can't see where I do it wrong. But I
keep
on
getting
the
runtime
error 2001 - You cancelled the previous
operation??
Please helt .. anyone!