Conditionally Format A Line?

1

1stAyd

Greetings, Access Novice here.

I have Line18 formatted as Visible = "NO" in Properties, and I want to make
it visible depending on the value of certain fields. Why doesn't this code
work when put in the "On Format" or "On Print" events of the Detail section?

If [Inventory Posting Group] = "RESALE" Then Line18.Visible = "YES"

BTW, I tried "TRUE" in place of "YES", and it still didn't work. TIA.
 
D

Duane Hookom

Assuming [Inventory Posting Group] is bound to a control in the report, you
should be able to use:
ME.Line18.Visible = (Me.[Inventory Posting Group] = "RESALE")
 
1

1stAyd

I tried that too, but didn't realize [Inventory Posting Group] had to be tied
to a report control. It's currently just on my source query. I'll try it
tomorrow and report back. Thanks!


Duane said:
Assuming [Inventory Posting Group] is bound to a control in the report, you
should be able to use:
ME.Line18.Visible = (Me.[Inventory Posting Group] = "RESALE")
Greetings, Access Novice here.
[quoted text clipped - 7 lines]
 
F

fredg

Greetings, Access Novice here.

I have Line18 formatted as Visible = "NO" in Properties, and I want to make
it visible depending on the value of certain fields. Why doesn't this code
work when put in the "On Format" or "On Print" events of the Detail section?

If [Inventory Posting Group] = "RESALE" Then Line18.Visible = "YES"

BTW, I tried "TRUE" in place of "YES", and it still didn't work. TIA.

You've turned the Yes (no quotes) into "Yes" (a string value).
Anyway in VBA it should have been True (without the quotes) not Yes.
Yes is not a VBA constant. True is.

If [Inventory Posting Group] = "RESALE" Then Line18.Visible = True

A simpler expression would be:
Line18.Visible = [Inventory Posting Group] = "RESALE"
 
1

1stAyd via AccessMonster.com

Still no luck. I created txtIPG, with the control source as [Inventory
Posting Group], and have this in the "On Format" event of the detail section:

=[Me].[Line18].[Visible]=([Me].[txtIPG]="RESALE")

I'm sure the answer will be something really simple.... TIA.

I tried that too, but didn't realize [Inventory Posting Group] had to be tied
to a report control.....
 
1

1stAyd via AccessMonster.com

Now I'm really confused. As an attempt to simplify, I put this line into "On
Format" of the "Detail" section:

=[Me].[Line18].[Visible]=True

but Line18 still isn't visible...... Thanks.
 
D

Duane Hookom

You must be in the code/module/vba window, not in the properties dialog.
There should not be any "=", just:
Me.[Line18].[Visible]=([Me].[txtIPG]="RESALE")

--
Duane Hookom
Microsoft Access MVP


1stAyd via AccessMonster.com said:
Still no luck. I created txtIPG, with the control source as [Inventory
Posting Group], and have this in the "On Format" event of the detail section:

=[Me].[Line18].[Visible]=([Me].[txtIPG]="RESALE")

I'm sure the answer will be something really simple.... TIA.

I tried that too, but didn't realize [Inventory Posting Group] had to be tied
to a report control.....
 
1

1stAyd via AccessMonster.com

Thanks, Duane, but I'll still SOL. In "On Format" of Detail it now says
"Event Procedure", and I copied exactly what you have into the code window.
The code window now says:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.[Line18].[Visible] = (Me.[txtIPG] = "RESALE")
End Sub

I tried to print instead of previewing, and I got this message: "A custom
macro in this report has failed to run, and is preventing the report from
rendering". In case it makes a difference, I'm using Access 2007. Thanks.


Duane said:
You must be in the code/module/vba window, not in the properties dialog.
There should not be any "=", just:
Me.[Line18].[Visible]=([Me].[txtIPG]="RESALE")
Still no luck. I created txtIPG, with the control source as [Inventory
Posting Group], and have this in the "On Format" event of the detail section:
[quoted text clipped - 5 lines]
I tried that too, but didn't realize [Inventory Posting Group] had to be tied
to a report control.....
 
F

fredg

Now I'm really confused. As an attempt to simplify, I put this line into "On
Format" of the "Detail" section:

=[Me].[Line18].[Visible]=True

but Line18 still isn't visible...... Thanks.

Not only do you appear to be confused but now I am as well <grin>

See Duane Hookums latest reply.
I suspect, as he does, that you are placing the code in the wrong
place.
Here is how to write code.
Click on the Event Tab of the report's Detail Section property sheet.
On the Format event line write:
[Event Procedure]
Click on the little button with 3 dots that appears on that line.
The Format event code window will appear.
The cursor will be flashing between 2 already existing lines of code.
Between those 2 lines write:

Line18.Visible = [Inventory Posting Group] = "RESALE"

Exit the window and save the VBA code.
 
D

Duane Hookom

Have you allow the application to run code? Are you viewing the report in
Print Preview?
The code should look something like this:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.[Line18].Visible = (Me.[txtIPG] = "RESALE")
End Sub
To see if this code is causing the issue, try comment out the line of code
like:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' Me.[Line18].Visible = (Me.[txtIPG] = "RESALE")
End Sub

--
Duane Hookom
MS Access MVP



1stAyd via AccessMonster.com said:
Thanks, Duane, but I'll still SOL. In "On Format" of Detail it now says
"Event Procedure", and I copied exactly what you have into the code
window.
The code window now says:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.[Line18].[Visible] = (Me.[txtIPG] = "RESALE")
End Sub

I tried to print instead of previewing, and I got this message: "A custom
macro in this report has failed to run, and is preventing the report from
rendering". In case it makes a difference, I'm using Access 2007.
Thanks.


Duane said:
You must be in the code/module/vba window, not in the properties dialog.
There should not be any "=", just:
Me.[Line18].[Visible]=([Me].[txtIPG]="RESALE")
Still no luck. I created txtIPG, with the control source as [Inventory
Posting Group], and have this in the "On Format" event of the detail
section:
[quoted text clipped - 5 lines]
I tried that too, but didn't realize [Inventory Posting Group] had to
be tied
to a report control.....
 
1

1stAyd via AccessMonster.com

My code looks good, but I haven't knowingly allowed code to run. How do I do
that? Thanks again, you guys are great.

Duane said:
Have you allow the application to run code? Are you viewing the report in
Print Preview?
The code should look something like this:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.[Line18].Visible = (Me.[txtIPG] = "RESALE")
End Sub
To see if this code is causing the issue, try comment out the line of code
like:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' Me.[Line18].Visible = (Me.[txtIPG] = "RESALE")
End Sub
Thanks, Duane, but I'll still SOL. In "On Format" of Detail it now says
"Event Procedure", and I copied exactly what you have into the code
[quoted text clipped - 21 lines]
 
1

1stAyd via AccessMonster.com

I managed to answer this one on my own. Thanks again, everyone.
My code looks good, but I haven't knowingly allowed code to run. How do I do
that? Thanks again, you guys are great.
Have you allow the application to run code? Are you viewing the report in
Print Preview?
[quoted text clipped - 13 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top