Problemer med at sende mail/rapport via Gmail
Jeg har en database med en vba-kode som gemmer en rapport og sender den via Gmail. Men når jeg kopierer denne kode over til en ny database, som ligger i samme mappe på computeren, får jeg fejlmelding. Hvorfor?"user defined type not defined"
Og teksten som er fed under er markeret med blåt i vba-kode vinduet.
Dim NewMail As CDO.Message
Her er koden jeg benytter:
[k]Dim Filnavn As String
Filnavn = " nr " & "" & Me!Id & " " & Dato & "" & " Hun" & ".pdf"
DoCmd.OpenReport "Hun", acViewPreview, , "Id = " & Id, acHidden
DoCmd.OutputTo acOutputReport, "Hun", "PDFFormat(*.pdf)", "c:\Users\Hun\Rapport" & Filnavn, False, "", , acExportQualityPrint
Dim NewMail As CDO.Message
Set NewMail = New CDO.Message
'Enable SSL Authentication
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
'Make SMTP authentication Enabled=true (1)
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Set the SMTP server and port Details
'To get these details you can get on Settings Page of your Gmail Account
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Set your credentials of your Gmail Account
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Gmail@gmail.com"
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "******"
'Update the configuration fields
NewMail.Configuration.Fields.Update
'Set All Email Properties
With NewMail
.Subject = "Rapport"
.From = "Gmail@gmail.com"
.To = "mail@gmail.com"
.CC = ""
.BCC = ""
.TextBody = "Vedlagt er en PDF-fil med rapporten"
.AddAttachment "c:\Users\Hun\Rapport" & Filnavn, False, ""
'.AddAttachment "c:\Users\Hun\Rapport" & Filnavn, False, ""
End With
NewMail.Send
MsgBox ("Mail er sendt")
'Set the NewMail Variable to Nothing
Set NewMail = Nothing
DoCmd.Close acReport, "Hun"[/k]