Results 1 to 10 of 10
  1. #1
    desk4tbc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    29

    Run Time Error 2465 In Report

    Hello again guys,



    I'm getting a Run-time error 2465 on a piece of code in a report. It works just fine as a form but not in a report. I was wondering if vba was handled differently between the two access objects and if there was a way to refer to data in a field not explicitly shown in the report.

    Below is the code:
    Code:
    If [1MC] = True Then chk1MC.Caption = "P"
    It refers to a Yes/No field that isn't shown on the report due to the standard checkbox being too small for the purposes here.

    Any help would be much appreciated!

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    error 2465 usually means Access can't find something. I assume it's looking for [1MC]. What is that?

    Also, your If statements should be closed with an "End If". Not sure if it was omitted from the code snippet or from the original source.

  3. #3
    desk4tbc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    29
    Thanks for the quick reply.

    [1MC] is the aforementioned Yes/No field. There isn't a control on the report with the name "1MC" but it is a field within the data source.

    Also for the If statement, Access doesn't freak out if its all in one line, but I've added it anyway and it still doesn't work .

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    You mention that it is not shown on the report. How did you bind the report to it's control source? I don't think you can refer to a table/query field that way. Try opening up a recordset on the table/query then reference that. So:
    Code:
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    set db = CurrentDB
    set rs = db.OpenRecordset("table/query Name", dbOpenDynaset)
    
    If rs![1MS] = True Then
    chk1MC.caption = "P"
    Else
    End If
    
    Set rs = nothing
    Set db = nothing

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In order to refer to a field in a RecordSource in a Report, the field must be bound to a control on the Report. The Control need not be visible, but it must be there.

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    ^^^^^ That too

  7. #7
    desk4tbc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    29
    Thanks guys.

    That's what I figured Rural, since the exact same code works fine in a form. I'll go change a few things around.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That has been the case for many revisions as I started with AccessXP and it was there. Glad we could help.

  9. #9
    desk4tbc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    29
    It works now that theres a reference to the field. Very odd behaviour as one object behaves one way while the other behaves contrary to the first. But thanks again for your expert help!

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You're welcome. Thanks for posting back with your success.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Run-Time error '2465'
    By hawkins in forum Access
    Replies: 6
    Last Post: 08-19-2011, 04:07 PM
  2. Not figuring out dlookup (RunTime 2465)
    By Gilligan in forum Access
    Replies: 10
    Last Post: 03-08-2011, 02:48 PM
  3. Replies: 2
    Last Post: 12-23-2010, 09:11 AM
  4. Replies: 2
    Last Post: 12-02-2010, 02:35 AM
  5. Replies: 1
    Last Post: 12-09-2005, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums