View Full Version : Report vba scripting


Espinoza84
05-30-2008, 08:53 AM
Hello, I cant figure this one out:

I have a textbox with control source [APPLICATION], when I run/execute the report, depending on the persons name and etc etc, the application will display either: house, hospital, or car.

At the same time I have 2 labels: Label1 and Label2. Nothing is bound btw.

What do I do if I want to hide Label1 (visible=false) but display Label2, if the result of the textbox with source [APPLICATION] is "house". and hide Label2 and display Label1, if the result of the textboxt with source [APPLICATION] is "hospital"

Can someone please code this for me?

KenHigg
05-30-2008, 09:20 AM
Several ways to do this. One is having both labels visible property set to false, put the following code in the reports on open event:

if me.application = "house" then
me.Label2.visible = True
else
me.Label1.visible = True
end if

Would this work for you?

Espinoza84
05-30-2008, 10:26 AM
thanks, I did this for my purposes:
Me.Label53.Visible = False
Me.Label85.Visible = False
If Me.Application = "House" Then
Me.Label53.Visible = True And Me.Label85.Visible = False
Else
Me.Label85.Visible = True And Me.Label53.Visible = False
End If

Because, my report is in DETAIL section and it loops so i needed to reset the labels back to false.

Espinoza84
05-30-2008, 10:34 AM
Now, that it is understood what I am trying to accomplish.

My real problem is that, I have a subreport in this report.

imagine the textbox [APPLICATION] is in the subreport, while the labels are in the main report (not in the subreport). Can I still accomplish my goal with the visibles(true/false) ?

Thank you in advance

KenHigg
05-30-2008, 04:26 PM
You should be able to, you just need to refer to the controls a little bit differently:

Me!mysubformname.form!Application = "House"

evanscamman
05-30-2008, 07:37 PM
How about this:


dim blnShow as Boolean
if Me!mysubformname.form!Application = "House" then
blnShow = True
else
blnShow = False
end if

Me.Label53.visible = blnShow
Me.Label58.visible = Not blnShow


Evan