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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code closes mysteriously? Please Help

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.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 but does not.It appears as if the instance of access is terminate.dSomething 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
Forms![FrmMailChoice]![NO] = rst!LicenseeNo
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
 
Did you try walking through the code by placing a breakpoint at thebeginning of it and using F8? That way, you could see at exactly which line it stops everything...

I have no idea what could be causing this...
 
At a glance, there is no error exit/checking. Any error would simply be 'promoted' to the calling process / procedure.

Second glance notes that you declare and instantiate Outlook within a loop, but you remove the instance out of the loop. Bad.

Additional 'not in my backyard' programming techniques, but they are trivial in comparision to these.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top