DoCmd.OutputTo AcReport <CRASHES>

Daveyk01

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

Access 2000.

stdocname = "CustomerWorkOrderRpt.XLS"
DoCmd.OutputTo acReport, "CustomerWorkOrderRpt", acFormatXLS, stdocname, True

Works, but Access closes, or crashes, immediately after creating the XLS spreadsheet.

I have tried AcFormatHTML, AcFormatSNP, acFormatRTF and all files are created from this report (I would perfer the RTF and SNP format). No matter what format the output is chosen, when I try to outputto acreport, my Access crashes.

When I use this function with a Query, such as with:
DoCmd.OutputTo acOutputQuery, "temp", acFormatXLS, NewFileName, True

I have no problems. It works perfect and Access continues to work. Its the acReport output option that is killing me. If I wanted to exit Access extreamly quickly I would use this function!

Access 2000, at times, drives me crazy.
 
Do you have any other code in with the Output code?
 
Do you have any other code in with the Output code?

Well here is an example that causes Access to instandly crash and exit:
Dim stdocname As String
Dim CC As String
Dim FaxNum As String
Dim Revision As Variant
Dim MyForm As Form
Dim Dprinter As Variant
'
Set MyForm = Forms!ServiceRecord
'
'Print cal cert
'
If IsNull(MyForm!CertVersion) Then
Revision = "B"
ElseIf MyForm!CertVersion = "" Then
Revision = "B"
Else
Revision = MyForm!CertVersion
End If
'
Dprinter = GetDefaultPrinter: MyForm!DefaultPrinter = Dprinter
TEMP = DLookup("DefaultCertPrinter", "Config")
SetDefaultPrinter (DLookup("DefaultCertPrinter", "Config"))
'DoCmd.OpenReport "CertReport_Rev" + Revision, acPreview
'
stdocname = "CertReport_Rev" + Revision
'
' This is an email so do it as a snapshot
CCFax = ""
FaxNum = "dave.kuhn@ge.com"
DoCmd.SendObject acReport, stdocname, acFormatSNP, FaxNum, CCFax, , "Certification Attached"

Now, the funning thing is that if stdocname = "EmailQuoteRpt" it works okay.

Both "EmailQuoteRpt" and "CertReport_Rev" are fairly simple reports. Maybe CertReport has some code in it that crashes Access (If send to printer, it works perfectly).

I am thinking that "CertReport_Revx" has a graphic/pic field in it. I don't if that could cause an issue or not. Error detection is not turned on in either report. Maybe the CertReport created a slighly larger snp file and that is an issue? I really am stumped.

This is a real strange issue.
 
Do you have any other code in with the Output code?

I found the offending lines of code on the CertReport report:

If fIsLoaded("ServiceRecord") Then
SetDefaultPrinter (Forms!ServiceRecord!DefaultPrinter)
Forms!ServiceRecord.SetFocus
DoCmd.Maximize
End If

I will investigate further....

Now this is weird. If I remark those lines out, Access doesn't crash. If I leave them un-remarked BUT I set every line with a break point, access crashes. Access crashes before it stop and ask me if I want to run the line of code.
 
Last edited:
Okay Bob,

Here is the offending function that is crashing the docmd.sendoutput command:

Function SetDefaultPrinter(strPrinterName As String) As Boolean
Dim strDeviceLine As String
Dim strBuffer As String
Dim lngbuf As Long

' get the full device string
'
strBuffer = Space(1024)
lngbuf = GetProfileString("PrinterPorts", strPrinterName, "", strBuffer, Len(strBuffer))

'Write out this new printer information in
' WIN.INI file for DEVICE item
If lngbuf > 0 Then

strDeviceLine = strPrinterName & "," & _
fstrDField(strBuffer, Chr(0), 1) & "," & _
fstrDField(strBuffer, Chr(0), 2)

Call WriteProfileString("windows", "Device", strDeviceLine)
SetDefaultPrinter = True

' Below is optional, and should be done. It updates the existing windows
' so the "default" printer icon changes. If you don't do the below..then
' you will often see more than one printer as the default! The reason *not*
' to do the SendMessage is that many open applications will now sense the change
' in printer. I vote to leave it in..but your case you might not want this.
'

Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "windows")

Else
SetDefaultPrinter = False
End If

End Function

I suspect it is the SendMessage call to the "User32" library, but I am not investigating an further and I do not need to change the default printer for this function.

Thanks for replying, it is rare now of days.
 
can I just add a big thanks here as well !
 
can I just add a big thanks here as well !


Well, that thread is going back a bit. With Access 2010, I now output most reports directly to PDF format and then let the user choose where to print them.

That solved a huge problem with me designing the reports in Windows 7 with Windows 7 printer drivers on my computer and then Windows XP users (most of out Serive Department still uses Windows XP) needed a Windows XP version of the same report formatted on an XP computer with XP drivers. That Mainly was a problem with all the Brother PC9500 Label printers we have connected to various machins. They work great but the XP and 7 drivers are very different when used with Access. Now a PDF is created, Adobe Acrobat 9/X Reader pops up, they see a preview of the sticker and then send it to the label printer of their choice. Works marvelous. Eliminated all that default printer setting code, much, much simpler. I also find the PDF out option in 2010 make a much better report preview function than the built-in preview. It truely is WYSIWYG, not WYSISWYG! WYSISWYG will drive you nuts!

Dave
 
We needed a way to preview access reports nicely, its a bit rough in access2003 so we used the outpt to rtf method to create an rtf file which we then preview in the stimulsoft report viewer..hope you know about stimulsoft btw..its just a zillion times better than crystal or access.

Thanks again
 
We needed a way to preview access reports nicely, its a bit rough in access2003 so we used the outpt to rtf method to create an rtf file which we then preview in the stimulsoft report viewer..hope you know about stimulsoft btw..its just a zillion times better than crystal or access.

Thanks again

No sorry, never heard of it. We are pretty limitted with software licensing of what can be put on the computers here. I just learned to live with the limitations of the Access report module (mouse screen magnifier options helps a lot on tiny label creation). I learned how to dynaically move report fields "up" when ones before it are empty and lots of other cool tricks. I really wish you could use a datagrid on a report but alas you can not. So I keep a dummy sub-report to base new reports on that need lots of fields or columized data, because the report editor can be a long task at times. The PDF output option in Access2010, to me, was sent down from Heaven. It cured a world of hurt for us. Before 2010, we were strickly Access 2000. We never saw Access 2003, 2007, XP, or whatever came in between.

Dave
 

Users who are viewing this thread

Back
Top Bottom