Error 2485 (1 Viewer)

bob fitz

AWF VIP
Local time
Today, 11:05
Joined
May 23, 2011
Messages
4,722
I am trying to use the following code to open a report in preview but I get the following error message:
Microsoft Access cannot find the object 'Custom Rpt.'
The error occurs at line 30.
I do not have a report called "Custom rpt" that is mentioned in the error message.
Code:
Private Sub cmdRpt_Click()
10    On Error GoTo Err_cmdRpt_Click

          Dim stDocName As String

20        stDocName = "rptReceipts"
30        DoCmd.OpenReport stDocName, acPreview, , "CoNameID = " & Me.cmbFindCo

Exit_cmdRpt_Click:
40        Exit Sub

Err_cmdRpt_Click:
50    Debug.Print Err.Description
60        If Err.Number = 2501 Then
70            Resume Exit_cmdRpt_Click
80        Else
90            Call ErrorLog(Err.Number, Err.Description, "cmdRpt_Click()", "frmReceipts", Erl, True)
100           Resume Exit_cmdRpt_Click
110       End If
End Sub
Does anyone have any ideas about what might be wrong here?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:05
Joined
Feb 19, 2013
Messages
16,610
is it possible you have a sub report in rptReceipts with a 'custom rpt' sourceobject?

What happens if you open the report manually?
 

jdraw

Super Moderator
Staff member
Local time
Today, 06:05
Joined
Jan 23, 2006
Messages
15,379
Bob,
No idea.
It doesn't seem to have used your Errorlog routine based on message format???
Is that significant??
Can you stop and step the code?
 

bob fitz

AWF VIP
Local time
Today, 11:05
Joined
May 23, 2011
Messages
4,722
Hi Chris

Thanks for your interest.
1) It does have a sub report but not with that source object.
2) Trying to open it manually produces the same error.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:05
Joined
Feb 19, 2013
Messages
16,610
Trying to open it manually produces the same error.
So the error is in the report. I would check any vba code for 'Custom rpt'. Being an object, this could be a control so it is possible the report has become corrupted. Try removing controls or alternatively just build a new report
 

bob fitz

AWF VIP
Local time
Today, 11:05
Joined
May 23, 2011
Messages
4,722
Chris and jdraw:

Thanks for your replies.

It seems that the error actually occurs in the reports OnOpen event in which I have the following line of code:
Code:
  Me.RecordSource = "SELECT [tblReceipts].[CoNameID], [tblCo].[CoName], [tblReceipts].[ReceiptID], [tblReceipts].[ReceiptDate], [tblReceipts].[Ref], [tblReceipts].[Amount], [tblSales].[SalesDate], [tblSales].[Ref], [tblSales].[Amount] FROM tblCo INNER JOIN (tblReceipts LEFT JOIN tblSales ON [tblReceipts].[ReceiptID]=[tblSales].[ReceiptID]) ON [tblCo].[CoNameID]=[tblReceipts].[CoNameID] WHERE ((([tblReceipts].[ReceiptDate])>=Format([Forms]![frmReceipts]![txtDateFrom],'dd/mm/yyyy') And ([tblReceipts].[ReceiptDate])<=Format([Forms]![frmReceipts]![txtDateTo],'dd/mm/yyyy'))); "
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:05
Joined
Feb 19, 2013
Messages
16,610
Does this query work (i.e. copy the code into a query sql window and run it) I presume frmReceipts is open and the from/to date fields updated

I note that your format is incorrect for the dates - should be US style

WHERE ((([tblReceipts].[ReceiptDate])>=Format([Forms]![frmReceipts]![txtDateFrom],'mm/dd/yyyy') And ([tblReceipts].[ReceiptDate])<=Format([Forms]![frmReceipts]![txtDateTo],'mm/dd/yyyy')))

Also why not have the recordsource there permanently and use the WHERE parameter for docmd.openreport?
 

bob fitz

AWF VIP
Local time
Today, 11:05
Joined
May 23, 2011
Messages
4,722
Does this query work (i.e. copy the code into a query sql window and run it) I presume frmReceipts is open and the from/to date fields updated

I note that your format is incorrect for the dates - should be US style

WHERE ((([tblReceipts].[ReceiptDate])>=Format([Forms]![frmReceipts]![txtDateFrom],'mm/dd/yyyy') And ([tblReceipts].[ReceiptDate])<=Format([Forms]![frmReceipts]![txtDateTo],'mm/dd/yyyy')))

Also why not have the recordsource there permanently and use the WHERE parameter for docmd.openreport?
Yes the query works if the form is open.
Thanks for your recommendation regarding the date format.
At some time in the past when trying to increase the speed of opening forms in a multiuser db I remember reading that forms and reports would open quicker if the recordsource property of anything that had such a property was assigned when the form/report opens rather than having it there permanently.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:05
Joined
Feb 19, 2013
Messages
16,610
they may do - depends on the volume of data.

But back to the problem in hand - I suspect the on open event is too late, have you tried the load event instead?

Other suggestion is to save the query and assign the query rather than the code
 

bob fitz

AWF VIP
Local time
Today, 11:05
Joined
May 23, 2011
Messages
4,722
they may do - depends on the volume of data.

But back to the problem in hand - I suspect the on open event is too late, have you tried the load event instead?

Other suggestion is to save the query and assign the query rather than the code
I've been playing with it.
I've removed EVERY control on the report and removed its code module and it still throws the error:eek::banghead:
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:05
Joined
Feb 19, 2013
Messages
16,610
in that case, sounds like the report is corrupted - suggest you create a new report from scratch
 

Users who are viewing this thread

Top Bottom