Results 1 to 3 of 3
  1. #1
    Williams485 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    42

    Runtime error 2467: ... object that is closed or doesn't exist

    Hello,



    I'm using the following code, which resides in a form (which is a subform on a main report):

    Code:
    Private Sub Report_Load()
        Me.lblWk1.Caption = CStr(Date - DatePart("w", Date) + 2)
        Me.lblWk2.Caption = CStr((Date - DatePart("w", Date) + 2) - 7)
        Me.lblWk3.Caption = CStr((Date - DatePart("w", Date) + 2) - 14)
        Me.lblWk4.Caption = CStr((Date - DatePart("w", Date) + 2) - 21)
        Me.lblWk5.Caption = CStr((Date - DatePart("w", Date) + 2) - 28)
        Me.lblWk6.Caption = CStr((Date - DatePart("w", Date) + 2) - 35)
        
        Me.txtWk1.ControlSource = CStr(Me.lblWk1.Caption)
        Me.txtWk2.ControlSource = CStr(Me.lblWk2.Caption)
        Me.txtWk3.ControlSource = CStr(Me.lblWk3.Caption)
        Me.txtWk4.ControlSource = CStr(Me.lblWk4.Caption)
        Me.txtWk5.ControlSource = CStr(Me.lblWk5.Caption)
        Me.txtWk6.ControlSource = CStr(Me.lblWk6.Caption)
    End Sub
    When I load the subform in it's own window, the code works without error and gives me the intended results (the report displays the results of a crosstab query which shows the last 6 weeks' data--so is dynamic, hence the code above). However, when the main form loads, I get "runtime error 2467: the expression you entered refers to an object that is closed or doesn't exist". I'm not quite sure how I should be referring to the object(s) to make sure the subform headers and controls display properly. How do I correctly reference the subform controls?

    Thanks

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I don't think you can use me. with a subform/subreport

    have you tried setting these in the ON LOAD event of the main form instead?

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I was wrong you can use me

    this is the code I used in the ON OPEN event of the subform:

    Code:
    Dim db
    Dim rst
    
    
    Set db = CurrentDb
    Set rst = db.OpenRecordset("qrycrosstab")
    For i = 1 To rst.Fields.Count - 1
        Me.Controls("lblwk" & i).Caption = rst.Fields(i).Name
        Me.Controls("txtwk" & i).ControlSource = CStr(rst.Fields(i).Name)
    Next i
    rst.Close
    Set rst = Nothing
    Set db = Nothing
    this assumes your data starts in the second column of your crosstab and your labels/text boxes are numbered from 1 to x.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-27-2013, 01:59 PM
  2. Replies: 1
    Last Post: 07-02-2013, 08:41 AM
  3. Runtime 2467 only on a Win 7 Machine
    By ilikebirds in forum Forms
    Replies: 3
    Last Post: 12-11-2012, 03:58 PM
  4. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  5. Replies: 5
    Last Post: 08-05-2009, 04:07 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