Back Style conditional on a text field

J

JohnB

Hi.

Is it possible to have the Back Style of a control dependant on content/no
content in a text field on the same form? I have an Image control called
imgTheImage and a text field txtImagePathAndFile. If the text field has
content, I want the Back Style of imgTheImage to be "Normal", otherwise
"Transparent". I was thinking of On Current event code. Can this be done?

Thanks for any help. JohnB
 
G

Guest

Private Form_Current()
If not IsNull(txtImagePathAndFile) then
imgTheImage.BackStyle = 1
Else
imgTheImage.BackStyle = 0
End Sub
 
J

JohnB

That works perfectly Brian. Thank you. JohnB

Brian said:
Private Form_Current()
If not IsNull(txtImagePathAndFile) then
imgTheImage.BackStyle = 1
Else
imgTheImage.BackStyle = 0
End Sub
 
G

Guest

You should also put the same code in the After Update evento of the control
so that when data is entered or deleted, it will change color.
 
J

JohnB

Hi again Brian.

I wonder if you are still watching this thread. If I don't hear from you
I'll repost. As I said earlier, you code works perfectly but I've noticed
that, when a new blank record is selected for data entry, text field
txtImagePathAndFile is somehow treated as having content. It's control
source is a DLookUp and shows as #Error in a blank record. Could the text
field be made truly IsNull in a new blank record or could you make a change
to your suggested code to ensure that this condition is treated as the field
being IsNull.

By the way, I tried turning your code on its head as follows, but that
didn't work either. It seems that when the text field is showing #Error it
neither has nor has not content.

Private Form_Current()
If IsNull(txtImagePathAndFile) then
imgTheImage.BackStyle = 0
Else
imgTheImage.BackStyle = 1
End Sub

Not the most major of problems, of course, but it would round things off
nicely if I could solve this.

Thanks again, JohnB
 

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