setting report Title to selected options label

  • Thread starter Thread starter Matt Williamson
  • Start date Start date
M

Matt Williamson

I have a form with an option group of 4 options. I want to set the Title of
a report to the Label associated to the option that is selected. I can't
figure out how.

So far, I've got the following:

I went ahead and Dim'd everything and set the object reference so I'd get
the intellisense and hopefully be able to figure it out, but so far I
haven't


Private Sub Report_Open(Cancel As Integer)

Dim f As Form
Dim opt As Control
Dim ctl As Control

Set f = Forms("New Cash Flows")
Set opt = f.Controls("grpFilter")

me.lblTitle2.caption = opt '??? can't figure out what I need here


'this didn't work either
'With Forms("New Cash Flows").Controls("grpFilter")
' Me.lblTitle2.Caption = .Controls(.Value).Caption
'End With

End Sub

TIA

Matt
 
-----Original Message-----
I have a form with an option group of 4 options. I want to set the Title of
a report to the Label associated to the option that is selected. I can't
figure out how.

So far, I've got the following:

I went ahead and Dim'd everything and set the object reference so I'd get
the intellisense and hopefully be able to figure it out, but so far I
haven't


Private Sub Report_Open(Cancel As Integer)

Dim f As Form
Dim opt As Control
Dim ctl As Control

Set f = Forms("New Cash Flows")
Set opt = f.Controls("grpFilter")

me.lblTitle2.caption = opt '??? can't figure out what I need here


'this didn't work either
'With Forms("New Cash Flows").Controls("grpFilter")
' Me.lblTitle2.Caption = .Controls(.Value).Caption
'End With

End Sub

TIA

Matt
Hi Matt, have you considered using the Report
OpenArguments? For example...

docmd.openreport ReportName:="myReport",OpenArgs:=Controls
("grpFilter").caption

.... may need a variable that stores the label onclick of
option button and assign to OpenArgs ...

in report_open()
if len(me.openargs)>0 then
lblTitle2.Caption =me.openargs
end if

Luck
Jonathan
 
I ended up with this, in case anyone else runs into this delima. I left in
my commented out code, because it helped me figure it out along the way, so
it might help someone else too. The loop helped me figure out that the
Option buttons OptionValues were out of order.

Private Sub Report_Open(Cancel As Integer)

Dim f As Form, n As Long
Dim grp As OptionGroup
Dim ctl As Control

Set f = Forms("New Cash Flows")
Set grp = f.Controls("grpFilter")

Me.lblTitle2.Caption = grp.Controls(grp.Value * 2).Caption

'Select Case grp.Value
' Case 1: Me.lblTitle2.Caption = grp.Controls(2).Caption
' Case 2: Me.lblTitle2.Caption = grp.Controls(4).Caption
' Case 3: Me.lblTitle2.Caption = grp.Controls(6).Caption
' Case 4: Me.lblTitle2.Caption = grp.Controls(8).Caption
'End Select

'For n = 0 To opt.Controls.Count - 1
' Debug.Print n & " :" & opt.Controls(n).Name
'Next

End Sub

HTH

Matt
 
Jonathan-

I'm using Access97. I don't see an OpenArgs property. I did see a few people
suggesting that in the NG archives as I was searching for the answer to my
issue, but I think that's a 2K+ option.

Since I didn't find any relevant hits, I posted what I did to resolve it for
the next person.

Thanks

Matt
 
Back
Top