Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    London, United Kingdom
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setting value of a report label (2002)

    I have created a dialog box form that opens a report. I would like a label on the report to display what the user has selected in the form's combo box . the following code is attached to the onclick event of the OK button on the dialog box that I have created.

    DoCmd.OpenReport "rptzTestingClientTrans", acViewPreview, , strFilter
    Reports("rptztestingclienttrans").Controls("lblDat es").Text = Me.cboDates.Text
    I get the following error "you can't refernece a property or method for a control unless the control has the focus.

    If anyone could point me in the right direction, I would be very grateful.

    Thanks

    Amanda

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: setting value of a report label (2002)

    Text is not a property of a label, Caption would be the property to use if this were possible. But you can't do it this way, you can't set anything in a report once it has been opened. Instead, use one of the two following methods:

    1) Put a text box on the report instead of the label, and set its Control Source to

    =[frmSomething]![cboDates]

    where frmSomething is the name of the form with the combo box and command button.

    2) Keep the label, and set its Caption in the On Open event of the report:

    Private Sub Report_Open(Cancel As Integer)
    Me.lblDates.Caption = Forms!frmSomething!cboDates
    End Sub

    where again frmSomething is the name of the form with the combo box and command button.

  3. #3
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    London, United Kingdom
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: setting value of a report label (2002)

    Thanks Hans, that works a treat!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •