Database Crashing! (1 Viewer)

Darrenc

Registered User.
Local time
Today, 15:44
Joined
Apr 30, 2004
Messages
62
I've come across a problem with my database, I’ve tried everything I can think of, and I’m still no wiser as to what’s causing the crashes. I hope someone can shed some light on what the problem might be.

I've created a database that uses a switchboard to navigate through the various forms, the switchboard is loaded (using the start up options) most of the database objects are switched off (like display database window), apart from 'allow full menus' and 'allow default shortcut menus'.

This reason I’ve given you the above information is that the error only occurs when the database is loaded through the start up options.
If I open the database bypassing the start-up options this error doesn't occur.

Now to the error:

I have various forms that have a button that will attempt to send an e-mail, its set up that the email doesn't send automatically but allows the user to edit the email before sending.
When the e-mail is created using the code below, and the user decides to cancel sending the email by pressing the 'close' button on the email, the database will lock up.

The first error message I get is:

The sendobject action was cancelled
You used a method of the DoCmd object to carry out an action in visual basic, but then clicked cancelling a dialog box.
For example, you used the close method to close a changed form, then clicked cancel in the dialog box that asks if you want to save the changes you made to the form.


The second message is my error trapping for cancelling the email, and then after that the form loses focus and I can't do anything to the database. It's still running because I have a clock on my form that’s still ticking away.

The only way I can close my database is to 'ctrl alt del' and 'end task' it. When I do this I get another error message saying

You can't exit the database now
If you are running a visual basic module that is using OLE or DDE, you may need to interrupt the module


And then the database closes.
I've noticed the crash only occurs when the 'display database window' option is turned off.
When its on then my error trapping deals with the closing of the email.

Code:
Private Sub MailCreditReport_Click()
On Error GoTo Err_MailCreditReport_Click
Dim stDocName As String

    If Me.Dirty Then
        DoCmd.RunCommand acCmdSaveRecord
        Else
    End If
    
    stDocName = "rptCreditAuthorisation"
    DoCmd.SendObject acReport, stDocName, acFormatRTF, , _
    , , , , True, False
    
Exit Sub
   
Exit_MailCreditReport_Click:
    Call ReportError
    Exit Sub

Err_MailCreditReport_Click:

    Select Case Err.Number
    
    Case "2501"
        MsgBox "User cancelled Sending E-mail(s). Please Resend", vbExclamation, "Sending Stopped"
    Exit Sub
    Case Else
        Resume Exit_MailCreditReport_Click
    End Select
    
End Sub

I've tried various things with the code like DoCmd.CancelEvent, but nothing seems to make any difference.

Any help would be greatly appreciated.
 

Darrenc

Registered User.
Local time
Today, 15:44
Joined
Apr 30, 2004
Messages
62
Has no-one got any idea's what's causing this error?

I'm under increasing pressure to finish this database I’ve been working on, and I don't really want to release it with such a serious bug.
 

MStCyr

New member
Local time
Today, 10:44
Joined
Sep 18, 2003
Messages
333
Have you tried to compile the project? .... ie. go in any module and Compile the project and see if any errors are generated.
 

Darrenc

Registered User.
Local time
Today, 15:44
Joined
Apr 30, 2004
Messages
62
Yep, I do that quite regularly, its not showing any errors.

Its really bugging me now, I can't understand why the error only occurs when the 'display database window' option is turned off.

Anyone else
 

Darrenc

Registered User.
Local time
Today, 15:44
Joined
Apr 30, 2004
Messages
62
I'd been asked if i ever found a fix for my problem, so i'm posting this just incase anyone else need help.

I did get round the problem, it took a fairly drastic change to get a fix but it turns out to be a much better way of sending things (emails in this case).

I ditched the SendObject method, i'm now using CreateObject directly into outlook. I won't pretend to know exactly how it works. :D

This is the basic code i'm now using.

Code:
Dim olapp           As Outlook.Application
Dim olNamespace     As Outlook.Namespace
Dim olfolder        As Outlook.MAPIFolder
Dim olMailItem      As Outlook.MailItem
Dim olattach        As Object
Dim strBodyText     As String

Set olapp = CreateObject("Outlook.Application")
Set olNamespace = olapp.GetNamespace("MAPI")
Set olfolder = olNamespace.GetDefaultFolder(olFolderInbox)
Set olMailItem = olfolder.Items.Add("IPM.Note")
Set olattach = olMailItem.Attachments

        strBodyText = "<HTML><BODY> Enter your email message here, because its HTML code you can do some nice things with the font and colours </BODY></HTML>"

With olMailItem
        .Subject = "Email Subject"
        .To = "Email Address"
        .CC = "CC Address"
        .HTMLBody = strBodyText
        .Importance = olImportanceHigh 'High importance
End With

    'You can add more than one attachment by useing the same line of code below
    olattach.Add "name of the file you want to attach"

    olMailItem.Send 'you can change this to olMailItem.Display if required
    
    Set objSafeMail = Nothing
    Set olMailItem = Nothing
    Set olfolder = Nothing
    Set olNamespace = Nothing
    Set olapp = Nothing

I know its a much more long winded way of sending an email but you can create some nice looking emails, you can attach .pdf reports, and as a nice side effect, i don't suffer the serious database crash anymore.

Hope someone finds this useful.
 

Daveyk01

Registered User.
Local time
Today, 07:44
Joined
Jul 3, 2007
Messages
144
Hello there,

your email sending example is not working for me. I am getting a "user defined type not defined error" on the first line:

Dim olapp As Outlook.Application

Did I have to reference a given library?
 

Daveyk01

Registered User.
Local time
Today, 07:44
Joined
Jul 3, 2007
Messages
144
Okay, I figured out how to reference Outlook. It works well to creat an email.

I am still having problems because what I want to send is the output of a report.

When I use the Docmd.OutputTo command to create a file, access seesm to lock-up on the second page of a two page report. I have tried HTML format, Snapshot format and RTF format. All lockup.

Your method works very well, but if I can not create the report to send, it doesn't help either.

I am getting more and more fustrated with Access 2000, but that is what we are locked in to.
 

Daveyk01

Registered User.
Local time
Today, 07:44
Joined
Jul 3, 2007
Messages
144
One more question concerning this.

When using this routine, Outlook pops up a window stating that a program is trying to automatically send an email on your behalf......"

Is there anyway in the VBA code to prevent this?
 

dmarek

New member
Local time
Today, 07:44
Joined
Apr 9, 2010
Messages
1
I fixed an issue exactly like the one in the first post by removing the "pop-up" property from the forms involved when generating the report email. There must be some conflict there, and I was surprised that it solved the problem. It took a lot of trial and error with many other ideas. I hope this helps save someone time.
 

melmore123

New member
Local time
Today, 10:44
Joined
Sep 23, 2010
Messages
1
Good call dmarek!


I was having that same problem. I never would of thought that simply changing that form property would cause so much trouble.
 

b_rocks

New member
Local time
Today, 07:44
Joined
Dec 17, 2009
Messages
3
I fixed an issue exactly like the one in the first post by removing the "pop-up" property from the forms involved when generating the report email. There must be some conflict there, and I was surprised that it solved the problem. It took a lot of trial and error with many other ideas. I hope this helps save someone time.

Much Thanks! It resolved it for me. You Are Da Man!!

B.
 

Daveyk01

Registered User.
Local time
Today, 07:44
Joined
Jul 3, 2007
Messages
144
After all these years, I am re-visiting this. I have been using a very similar routines very well and still using it. In a new project, I am using it.

Unlike the old project, I put a "Option Explicit" at the top of the module.

When I compile the datbase I get an error "!Variable Not Defined" for this line:

Set objSafeMail = Nothing

What would "objSafeMail" be defined as and is that statement really needed?

Dave
 

Users who are viewing this thread

Top Bottom