How to change textbox backcolour based on value in a a combobox when printing form (1 Viewer)

Harry Paraskeva

Registered User.
Local time
Today, 13:16
Joined
Sep 8, 2013
Messages
67
I'm certain that the solution to this one is rather simple...but I just can't figure it out!

I have a form with a subform which need get printed as a PDF. There is a textbox on the subform which gets its backcolour property set based on the value entered in a combobox also on the subform. I have included appropriate VBA both in the After Update of the controlling combobox and the OnCurrent and OnLoad subform properties.

Code:
If Me.Type = "A" Then
Me.When.BackColor = RGB(232, 139, 0)
ElseIf Me.Type = "B" Then
Me.When.BackColor = RGB(138, 146, 0)
ElseIf Me.Type = "C" Then
Me.When.BackColor = RGB(239, 172, 0)
End If

However, when I hit the Print button the PDF does not reflect the backcolour changes for each record in the subform, most likely because it ignores the OnCurrent code as it loops through the records of the subform. Is there any way to do this?

Thank you for any help!
 

Mark_

Longboard on the internet
Local time
Today, 03:16
Joined
Sep 12, 2017
Messages
2,111
Is the subform a continuous form? If so, you would be looking for the On_Paint event. Please not that it isn't always a nice way to do this as you can only ensure it uses a value also on that instance of the continuous form with any assurance.

If there is something in the subform that you can reference (even if you put it on the screen as a 0 height/width text box) this will work much better.

Continuous forms also have issues when there are less records to show than the area given over to the continuous form.

Any chance, as you want to send this to a PDF, that you can make a report that does what you want?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 20:16
Joined
Jan 20, 2009
Messages
12,852
Use Conditional Formatting
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:16
Joined
May 7, 2009
Messages
19,234
you may remove all your code
that changes the color of the
textbox.
instead use Conditional formatting
on that textbox.

use "Expression Is"
from the combobox selection.
make three conditional formats

Expression Is [Type]="A"
Expression Is [Type]="B"
Expression Is [Type]="C"
 

Harry Paraskeva

Registered User.
Local time
Today, 13:16
Joined
Sep 8, 2013
Messages
67
you may remove all your code
that changes the color of the
textbox.
instead use Conditional formatting
on that textbox.

use "Expression Is"
from the combobox selection.
make three conditional formats

Expression Is [Type]="A"
Expression Is [Type]="B"
Expression Is [Type]="C"

Entirely correct! I did not think of the simple solution and went for the hard one. :) Thank you!
 

Harry Paraskeva

Registered User.
Local time
Today, 13:16
Joined
Sep 8, 2013
Messages
67
Is the subform a continuous form? If so, you would be looking for the On_Paint event. Please not that it isn't always a nice way to do this as you can only ensure it uses a value also on that instance of the continuous form with any assurance.

If there is something in the subform that you can reference (even if you put it on the screen as a 0 height/width text box) this will work much better.

Continuous forms also have issues when there are less records to show than the area given over to the continuous form.

Any chance, as you want to send this to a PDF, that you can make a report that does what you want?

It is not a continuous form, it is single record, but it prints continuously. I wanted to make it this way, so that the interface for the user is also the final product. It's for a micro-task, not something big, hence no need to produce reports. Thank you for your thoughts!
 

Users who are viewing this thread

Top Bottom