[AccessD] Application-defined or object-defined error (Error 2465) in CommonDialog1

Bud Goss bgoss711 at ameritech.net
Wed May 12 12:12:02 CDT 2010


I am converting an old Access97 application to Access2003. 
This database uses a routine for print preview reports that evokes the common dialog box for printing.
 
For existing reports in the Access 2003 database code continues to workOK. 
But when I create a new report in the Access 2003 database and use this routine I get an error 2465 – Application-defined or object-defined error. This error occurs with XP and Windows7 PCs.
 
In one case when I created a new report, it failed with this error. Several hours after the first attempt, it worked OK. But the next day, it failed with this error again and continues to fail. 
 
 The code is listed below and I have commented the statement that generated the error.
 
I have Googled this issue and found many items for Error2465 but so far have found none that address the error with the use of    CommonDialog1 code.
 
Listed below is one solution from Google that I tried – but it does NOT eliminate the error.
(FIX: Remove DAO 3.6 from Access 97, return to DAO 3.51. Click Start | Run, paste this in:
Regsvr32.exe "C:\Program Files\Common Files\Microsoft Shared\DAO\DAO350.DLL" and hit return. You should see a message that the library was successfully registered.  
 
Any help would be greatly appreciated. - Code listed below with error point
commented.
 

Private Sub BtnPrint_Click()
On Error GoTo Err_BtnPrint_Click
Dim BeginPage, EndPage, NumCopies, i
       
   
    DoCmd.SelectObject A_REPORT, Reports(Reports.count - 1).Name
    CommonDialog1.CancelError = True
  
    Const PAGENUMBERS = &H2&
    Const cdlPDPAGENUMS = &H2&
    Const DISABLESELECT = &H4&
    Const ALLPAGES = &H0&
    CommonDialog1.flags = cdlPDPAGENUMS + DISABLESELECT + ALLPAGES
    CommonDialog1.Min = 1
    
    ‘  Application-defined or object-defined error - Error 2465 
     ‘ will occur on next statement 
    CommonDialog1.Max = Reports(Reports.count - 1).PagesAmt
      
    CommonDialog1.FromPage = 1
    CommonDialog1.ToPage = Reports(Reports.count - 1).PagesAmt
    CommonDialog1.ShowPrinter
    BeginPage = CommonDialog1.FromPage
    EndPage = CommonDialog1.ToPage
    NumCopies = CommonDialog1.Copies
    For i = 1 To NumCopies
    If BeginPage = 0 Then
        DoCmd.PrintOut acPrintAll
    Else
        DoCmd.PrintOut acPages, BeginPage, EndPage, , NumCopies
    End If
    Next i
    Exit Sub
 
Exit_BtnPrint_Click:
    Exit Sub
 
Err_BtnPrint_Click:
    
    MsgBox "ERROR NUMBER " & Err.Number
    MsgBox Error$, , SOFTNAME
    Resume Exit_BtnPrint_Click
    
End Sub


More information about the AccessD mailing list