preview/print execution results in database close-down

J

JohnLute

I'm experiencing a database close-down whenever I execute a preview and print
button. Upon execution a dialog box pops up: "MS Access has encountered a
problem and must be closed."

I've reviewed the preview button code and don't see any problems. Does
anyone see any:

Private Sub Preview_Click()
On Error GoTo Err_Preview_Click

Dim strDocName As String
Dim stLinkCriteria As String

'Check to see that ending date is later than beginning date.
If IsDate(BeginningDate) And IsDate(EndingDate) Then
If EndingDate < BeginningDate Then
MsgBox "The ending date must be later than the beginning date."
SelectDate.SetFocus
Exit Sub
End If
Else
MsgBox "Please use a valid date for the beginning date and ending
date."
Exit Sub
End If

strDocName = Me!SelectReport

If strDocName = "Complaint Rate Chart" Then
DoCmd.OpenForm "MsgBoxComplaintRateChart", , , stLinkCriteria
Else
DoCmd.OpenReport strDocName, acPreview
End If

Exit_Preview_Click:
Exit Sub

Err_Preview_Click:
If Err = ConErrRptCanceled Then
Resume Exit_Preview_Click
Else
MsgBox Err.Description
Resume Exit_Preview_Click
End If

End Sub

Thanks for your help!!!
 
A

Allen Browne

The problem is not with your code.
Something else is wrong with the database.

If this report and others print and preview fine when NOT using this button,
then it is unlikely to be a printer issue. It's more likely to be either
corrupted code (needs decompile) or naming confusion (Name AutoCorrupt.)

This sequence should get you going:

1. Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Explanation of why:
http://allenbrowne.com/bug-03.html

2. Compact the database to get rid of this junk:
Tools | Database Utilities | Compact

3. Close Access. Make a backup copy of the file. Decompile the database by
entering something like this at the command prompt while Access is not
running. It is all one line, and include the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

4. Open Access, and compact again.

5. Open a code window.
Choose References from the Tools menu.
Uncheck any references you do not need.
For a list of the ones you typically need in your version of Access, see:
http://allenbrowne.com/ser-38.html

6. Still in the code window, choose Compile from the Debug menu.
Fix any errors, and repeat until it compiles okay.

At this point, you should have a database where the name-autocorrect errors
are gone, the indexes are repaired, inconsistencies between the text- and
compiled-versions of the code are fixed, and reference ambiguities are
resolved.

If it is still a problem, the next step would be to get Access to rebuild
the database for you. Follow the steps for the first symptom in this
article:
Recovering from Corruption
at:
http://allenbrowne.com/ser-47.html
 
J

JohnLute

SUPER! Thanks, Allen. That did the trick. Excellent!

I think I'm halfway there. In System Objects view all of the tables appear
with a black arrow pointing at them. When I try to open them an error dialog
appears: 'H:\ComplaintDB\ComplaintData.mdb' is not a valid path. Make sure
the path name is spelled correctly and that you are connected to the server
on which the file resides.

I'm working on a copy of the "corrupted" database. My copy is located on my
C:\ and the corrupted original is located on our H:\ drive.

This is all foreign to me. Would you know how I could correct this so that
the db functions regardless of what drive it's on?

Thanks for all your help and info!
 
A

Allen Browne

I think you are asking how to reattach all the attached tables to the C:
drive instead of H: drive?

You might be able to use the Linked Table Manger, under:
Tools | Dataase Utilities

It's also really easy to just delete the linked tables from your database
(only those with the arrow in their icon), and then attach them from the
right database:
File | Get External | Link

If you wanted to do this programmatically, there's a module in
solutions.mdb, which you can download from:
http://msdn.microsoft.com/library/officedev/bapp2000/mdbdownload.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top