Further help with backstyle conditional on field content

J

JohnB

Hi.

Some days ago 'Brian' gave me a good solution to having the back style of an
Image control conditional on content/no content of field
txtImagePathAndFile. Brians solution is the following:

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

As I said in the original thread, this works perfectly but there is now a
small tweak that's needed. When a new blank record is selected for data
entry, text field txtImagePathAndFile is somehow treated as having content.
It's controlsource 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 a change
be made to Brians code to ensure that this condition is treated as the field
being IsNull.

By the way, I tried turning the 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 for any help. JohnB
 
T

tina

i'm guessing that the DLookUp() function has a criteria expression that
refers to a control in the form's current record. when that control has no
value, in a new record, the DLookUp() function returns an error (at least
that's what happened in my test). if my guess is correct, try the following
in the ControlSource of textbox txtImagePathAndFile, as

=IIf([ControlName] Is Null, Null, DLookUp(...))

use the complete DLookUp syntax, of course. and replace ControlName with the
name of the form's control that's referred to in the DLookUp() function's
criteria expression.

hth
 
J

JohnB

Hi Tina.

Sorry for the delay in responding. Good news - that worked a treat!

Thank you very much. JohnB

tina said:
i'm guessing that the DLookUp() function has a criteria expression that
refers to a control in the form's current record. when that control has no
value, in a new record, the DLookUp() function returns an error (at least
that's what happened in my test). if my guess is correct, try the following
in the ControlSource of textbox txtImagePathAndFile, as

=IIf([ControlName] Is Null, Null, DLookUp(...))

use the complete DLookUp syntax, of course. and replace ControlName with the
name of the form's control that's referred to in the DLookUp() function's
criteria expression.

hth


JohnB said:
Hi.

Some days ago 'Brian' gave me a good solution to having the back style
of
an
Image control conditional on content/no content of field
txtImagePathAndFile. Brians solution is the following:

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

As I said in the original thread, this works perfectly but there is now a
small tweak that's needed. When a new blank record is selected for data
entry, text field txtImagePathAndFile is somehow treated as having content.
It's controlsource 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 a change
be made to Brians code to ensure that this condition is treated as the field
being IsNull.

By the way, I tried turning the 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 for any help. JohnB
 
T

tina

you're welcome :)


JohnB said:
Hi Tina.

Sorry for the delay in responding. Good news - that worked a treat!

Thank you very much. JohnB

tina said:
i'm guessing that the DLookUp() function has a criteria expression that
refers to a control in the form's current record. when that control has no
value, in a new record, the DLookUp() function returns an error (at least
that's what happened in my test). if my guess is correct, try the following
in the ControlSource of textbox txtImagePathAndFile, as

=IIf([ControlName] Is Null, Null, DLookUp(...))

use the complete DLookUp syntax, of course. and replace ControlName with the
name of the form's control that's referred to in the DLookUp() function's
criteria expression.

hth


JohnB said:
Hi.

Some days ago 'Brian' gave me a good solution to having the back style
of
an
Image control conditional on content/no content of field
txtImagePathAndFile. Brians solution is the following:

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

As I said in the original thread, this works perfectly but there is
now
 

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