desperatly trying to save email message..

R

rocco

Hello,
I have wrote code in Access to create an email message with an attachment (
a .zip file choosen from user through a FileDialogPicker.
I would like to save the messa into the Draft folder...now..it seems I'm
having trouble with the save method. Debugging says it is all right...but the
save method shows in *lowercase* (i.e. mssg.save instead of mssg.Save) ...
which sounds like an alert that something is going wrong. If I use the SaveAs
method, instead, it shows in the *first letter capitalized* fashion...so
what's wrong with the save method? I'm on this thing from this morning and I
really canno tfigured out what' wrong. If run the procedure it goes all the
way down without any error...but the message is not saved.
Here is my code:

On Error GoTo email_err

Dim objol As Object
On Error Resume Next
Set objol = GetObject("Outlook.application")
Dim msgg As Object
Dim vrtSelectedItem As Variant
With objol
Set msgg = .CreateItem(olMailItem)
End With

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
..Title = "Selezionare il file di back up da inviare"
..InitialFileName = CurrentProject.Path & "\ArchivioDati\"
..Filters.Clear
..ButtonName = "Seleziona"
..Filters.ADD "zipped files", "*.zip"

If .show=-1 then
For Each vrtSelectedItem In .SelectedItems
msgg.Attachments.ADD vrtSelectedItem
Next vrtSelectedItem
msgg.To = InputBox("Indicare l'indirizzo di posta elettronica a cui
inviare il messaggio: ", "Indirizzo em@il del destinatario")
msgg.Subject = "Invio delle tabelle del database da: " &
CurrentUser() & "; il: " & Now()
msgg.save
Dim myNameSpace As Outlook.NameSpace
Dim myDraft As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Set myNameSpace = objol.GetNamespace("MAPI")
Set myDestFolder = myNameSpace.Folders(olFolderDrafts)
msgg.Move myDestFolder

Set myNameSpace = Nothing
Set myDestFolder = Nothing
Else
Set objol = Nothing
Set msgg = Nothing
Exit Sub
End If
End With

Exit Sub

email_err:
If Err.Number = 429 Then
Set objol = CreateObject("Outlook.application")
Resume Next
Else
MsgBox "La procedura ha riscontrato un errore. Controllare che:" + vbCrLf + _
"a) sia stata fatta l'esportazione delle tabelle" + vbCrLf + _
"b) siano state zippate in un unico file .zip le tabelle esportate" + vbCrLf
+ _
"c) Microsoft Outlook sia installato e configurato sul proprio sistema.",
vbCritical, "Errore nella procedura!"
Set objol = Nothing
Exit Sub
End If

Thanks!
Rocco
 
S

Sue Mosher [MVP-Outlook]

You don't need to move the item into the Drafts folder. New unsent messages save in Drafts automatically. I'd try taking out the Move statement.

Why aren't you declaring an Outlook.Application object and Outlook.MailItem object in these statements:

Dim objol As Object
Dim msgg As Object

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
R

rocco

Actually...if I don't move they will be saved in the ...Inbox folder - which
is the default folder. This at least happens on my pc...
 
S

Sue Mosher [MVP-Outlook]

Actually...if I don't move they will be saved in the ...Inbox folder - which
is the default folder. This at least happens on my pc...

You mean you have the Inbox set in Outlook as the default folder for unsent messages? Wouldn't you want to honor the user's setting?

Still looking for an answer here.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

 
D

Dmitry Streblechenko

That's an indication that you do not have a MAPI session at the time
CreateItem is called.
Do call Namespace.Logon.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
R

rocco

thanks both for your reply and for trying to help me.

For Sue:
well... Actually... I built this procedure some time ago (with minor
changes, just the fact that now you can choose the attach through a
FileDialog and that this time I'm using late binding) and also on other pc's
it happens that the email was saved in the inbox folder. And somewhere I have
found out that the INBOX is the default folder...by default? But I can be (I
would if this will solve the issue) wrong.

For Dmitry:
since I'm kind of newbie with Outolook programming, can you please explain
what you meant? If you meant that I haven't an Outlook session running, the
answer is yes. And I would like to be able to run my procedure without having
to launch that application.

For both:
I really appreciate your efforts, but the procedure works just fine...it
hust the save methiod that doesn't fire. Again, if I wrote mssg.saveas and
hit enter, it changes into mssg.SaveAs which suggest that it understand the
syntax. if I wrote mssg.save and hit enter...it stay mssg.save...
 
D

Dmitry Streblechenko

Isn't your code already launching it?
Add the following code immediately after retrieving objol:

set NS = objol.GetNamespace("MAPI")
NS.Logon

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

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