email send (attachment ) but only when (1 Viewer)

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 07:54
Joined
Nov 8, 2005
Messages
3,294
blonde moment


Dim EmailApp, NameSpace, EmailSend As Object

Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)

the above works great
and so does -
EmailSend.Attachments.Add ([attachmentfld])

however if I have no attachment - it throws a wobble - I know its simple - but cannot see it - - something along the lines of if attachmentfld is not null then ?

points would be appricated
 

Access_guy49

Registered User.
Local time
Today, 10:54
Joined
Sep 7, 2007
Messages
462
if Isnull([Attachment field]) then
'Do nothing, or do something, your choice
else
EmailSend.Attachments.Add ([attachmentfld])
end if


But this doesn't test to make sure that the attachment field has a valid file that actually exists in the computer.
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 07:54
Joined
Nov 8, 2005
Messages
3,294
do nothing - how do you get it to do nothing ?
 

Access_guy49

Registered User.
Local time
Today, 10:54
Joined
Sep 7, 2007
Messages
462
leave it blank. or do as i did, and just put a comment that says do nothing.

Just as a note for VBA inase you are not familure, Comments turn green and are marked with a ' the are NOT part of the code execution, they are designed so that programmers can comment their code and save hundereds of hours for future programmers.

not comment
'comment

(Sorry if it sounds like i'm saying really basic stuff that you already know, I just wanted to be clear, I have known some people who NEVER...EVER used comments..)
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 07:54
Joined
Nov 8, 2005
Messages
3,294
no it throws a wobbly
runtime 2465 error -



If IsNull([Attachment field]) Then
'do nothing'




Else
EmailSend.Attachments.Add ([attachmentfld])
End If
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 07:54
Joined
Nov 8, 2005
Messages
3,294
No problems with the green text - I leave notes for myself - when I get drag off doing paid work - then I come back to a problem - I read my "green notes"
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 07:54
Joined
Nov 8, 2005
Messages
3,294
re - your comment-
But this doesn't test to make sure that the attachment field has a valid file that actually exists in the computer

They pick the file from a drop down the location of which is stored in a table - so they cannot pick any file just the ones from the table
 

Access_guy49

Registered User.
Local time
Today, 10:54
Joined
Sep 7, 2007
Messages
462
Have you ever stepped through code? I would recomend trying it. place a stop at the start of that if statement and see if it actually goes into the 'do nothing
Or if it see's it as ELSE
it might be a case of the field not actually being null but rather "" in which case you would want to also test for that..
else if attachmentfld = "" then
'also do nothing
 

Access_guy49

Registered User.
Local time
Today, 10:54
Joined
Sep 7, 2007
Messages
462
The only other thing i can think of is that your control is not named attachmentfld.
I believe this error can be caused if you get the name wrong.
use me.attachmentfld just to make sure you don't have a typo
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 07:54
Joined
Nov 8, 2005
Messages
3,294
Typo- put me in a field and shootme
I cut and pasted the code and didn't check it I had shortend field to fld

- I am a twit-

Big thansk AG -49

If IsNull([Attachment field]) Then
'do nothing'

Else
EmailSend.Attachments.Add ([attachmentfld])
End If
 

Users who are viewing this thread

Top Bottom