Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook code seem to not close

Status
Not open for further replies.

romnew

Programmer
Feb 27, 2002
44
ZA
Hi,
Question: Access2000
I activate the code below from a form.
The code does what is aimed at but although the particular e-mails are created the code does not finish.
A dark grey square forms itself over the form from which the code was activated. The code as can be seen closes this form. Something is missing and I am stuck.
Can any one please help
The code:
Function OutputSnapshotFile()
Dim strOutputFormat As String, strName As String, strPath As String
DoCmd.Hourglass True
strOutputFormat = "Snapshot Format"
Dim db As Database, rst As Recordset
Dim File As String, Name As String, DM As String, Ext As String
Set db = CurrentDb()
Set rst = db.OpenRecordset("LicenseeMails", dbOpenTable)
rst.MoveFirst
DM = Mid(rst![Datum], 6, 2)
Ext = DM & ".snp"
Do While Not rst.EOF
If rst.EOF = False Then
Forms![FrmMailChoice]![NO] = rst!LicenseeNo
End If
Name = ("Rem" & rst![LicenseeNo] & Ext)

File = "C:\RptContainer\" & Name
strPath = File
strName = "ReminderNoReportsMails"

DoCmd.OutputTo acOutputReport, "ReminderNoReportsMails", acFormatSNP, strPath

'Create email
Dim Objoutlook As Outlook.Application
Dim objNewMail As Outlook.MailItem
Dim objnamespace As Outlook.NameSpace
Dim varRecip As Variant
Dim strSubject As String
Dim strMessage As String
Dim varAttach1 As Variant

Set Objoutlook = New Outlook.Application ' Application object.
Set objnamespace = Objoutlook.GetNamespace("MAPI") ' Namespace object.
Set objNewMail = Objoutlook.CreateItem(olMailItem)

varAttach1 = strPath
strSubject = "Report attachment:" & Name
strMessage = "Urgent Reminder! No Royalty Report!. Save and print it."
objNewMail.Recipients.Add rst![LicEMail]
objNewMail.Subject = strSubject
objNewMail.Body = strMessage
objNewMail.Attachments.Add varAttach1
objNewMail.Display
objNewMail.Send

rst.MoveNext
Loop
DoCmd.Hourglass False
rst.Close
DoCmd.Close acForm, "FrmMailChoice"
DoCmd.SetWarnings False
DoCmd.OpenQuery "QryUpdateRoyControlToZero"
DoCmd.OpenForm "FrmDisplay"
Set rst = Nothing
Set Objoutlook = Nothing
Set objnamespace = Nothing
Set objNewMail = Nothing
Set db = Nothing

End Function
 
Hi.

Why have the Docmd.Setwarnings False ? Remove this and see if the problem occurs after this point.

A good way to debug is to place a Msgbox("Hello") in various places (but only 1 at any 1 time). Then watch what happens before the debug box. This should give you a better understanding of where the error is occuring.

Regards,
Mr Big
 
Hi Mr Big,
Set warnings false only applies to the last query updating RoyControltoZero.
What appears to be happening is that the code runs doing everything up to the loop when EOF is reached. It appears then that something? closes the database.The code instructions after the loop is not done.
I have debugged as you suggested but no luck
I just can't get behind the behavior of this run.
Any other suggestions anybody!
Romnew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top