PDA

View Full Version : Solved: Conditional Report fields



jauner
12-27-2005, 08:37 AM
Is there a way in access to change a label on a report based on a certain condition and changed its associated detail line field control source?

Not really sure what event to do it in or what the syntax should be off-hand.

The other thing I would like to do is to be able to change the conditional field in a grouping scenario programmatically. What I mean is lets say i create a report that is grouped by consultant. I would like to change it to AccountConsultant or ManagingConsultant based on report Criteria. Is that possible?

nullZero
12-27-2005, 10:58 AM
Hey, Not sure if I get the second part of the question but your first part regarding changing label captions based on field data is totally doable.

try the following and see how it works for you...


Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim strCaption, strCriteria As String

strCriteria = "your expected value"

' Modify values and field & control names as needed
If Me!yourfield = strCriteria Then
strCaption = "your caption if true"
Else
strCaption = "your caption if false"
End If

Me.yourLabel.Caption = strCaption
End Sub

jauner
01-05-2006, 02:16 PM
Thanks that part worked great. I ended creating extra reports for grouping differences. The only thing I had to do different is add to the Report.Open event instead. This was because I got a message about not being able to change the control source of a field while it was in print preview mode.

geekgirlau
01-09-2006, 02:12 AM
Re the conditional grouping, can you build that as a calculated field in your query?