Change background colour of field on form

R

Robin Chapple

I have a membership database where the Partner name is recorded if
there is a partner. We also record partner birthday so that we can
send birthday greetings.

Some of our members record partner name but forget to enter the
birthday.

On the form I need to change the background colour of the [pname]
field if the [pbornday] field is blank probably using the form
OnCurrent event.

Is this possible?

Thanks,

Robin Chapple
 
E

Ed Warren

Try:

OnCurrentEvent

if me.pbonday.text = null then
me.pname.background = vbRed
end if

Or you can make the pbornday field a required field in the table and they
can't save a record without a date.

Hope this helps

Ed Warren
 
F

fredg

Robin said:
I have a membership database where the Partner name is recorded if
there is a partner. We also record partner birthday so that we can
send birthday greetings.

Some of our members record partner name but forget to enter the
birthday.

On the form I need to change the background colour of the [pname]
field if the [pbornday] field is blank probably using the form
OnCurrent event.

Is this possible?

Thanks,

Robin Chapple
Robbin,

You can do this in the [pname] control's Conditional Formatting property
if you are using Access 2000 or later:
Select the [pname] control.
click Format + Conditonal formatting.
Set the Condition1 drop-down to
Expression Is
In the text box along side this drop-down, write:
IsNull([pbornday])

Select the colors.
Save the change.

The below code will work for all versions.
In the Form's Current event, as well as in the [pbornday] AfterUpdate
event (change the colors as desired):

If IsNull([pbornday] Then
[pname].backcolor = vbRed
[pname].forecolor = vbYellow
Else
[pname].backcolor = vbWhite
[pname].forecolor = vbBlack
End If
 
R

Robin Chapple

Fred,

The below code will work for all versions.
In the Form's Current event, as well as in the [pbornday] AfterUpdate
event (change the colors as desired):

If IsNull([pbornday] Then
[pname].backcolor = vbRed
[pname].forecolor = vbYellow
Else
[pname].backcolor = vbWhite
[pname].forecolor = vbBlack
End If

As predicted I tried this and had this error message:

"" Run time error 438
Object does not support this property or method ""

Robin
 
R

Robin Chapple

Fred,

Thanks. I was unaware of the conditional formatting option. That will
get used in the future.

The scheme works well but I need to ignore the colour change if there
is not a partner name mentioned.

I have tried this and other variations without success:

IsNull([spbornday]) And ([spname]) Is Not Null

The field names are different from my original question.

Thanks,

Robin

Robbin,

You can do this in the [pname] control's Conditional Formatting property
if you are using Access 2000 or later:
Select the [pname] control.
click Format + Conditonal formatting.
Set the Condition1 drop-down to
Expression Is
In the text box along side this drop-down, write:
IsNull([pbornday])

Select the colors.
Save the change.

The below code will work for all versions.
In the Form's Current event, as well as in the [pbornday] AfterUpdate
event (change the colors as desired):

If IsNull([pbornday] Then
[pname].backcolor = vbRed
[pname].forecolor = vbYellow
Else
[pname].backcolor = vbWhite
[pname].forecolor = vbBlack
End If


Robin said:
I have a membership database where the Partner name is recorded if
there is a partner. We also record partner birthday so that we can
send birthday greetings.

Some of our members record partner name but forget to enter the
birthday.

On the form I need to change the background colour of the [pname]
field if the [pbornday] field is blank probably using the form
OnCurrent event.

Is this possible?

Thanks,

Robin Chapple
 
R

Robin Chapple

Ed,

I'm trying all suggestions.

Error message:

"" You can't reference a property or method for a control unless the
control has the focus ""

Robin

Try:

OnCurrentEvent

if me.pbonday.text = null then
me.pname.background = vbRed
end if

Or you can make the pbornday field a required field in the table and they
can't save a record without a date.

Hope this helps

Ed Warren

Robin Chapple said:
I have a membership database where the Partner name is recorded if
there is a partner. We also record partner birthday so that we can
send birthday greetings.

Some of our members record partner name but forget to enter the
birthday.

On the form I need to change the background colour of the [pname]
field if the [pbornday] field is blank probably using the form
OnCurrent event.

Is this possible?

Thanks,

Robin Chapple
 
F

Fredg

Robbin,
Sorry, I left off a parenthesis,
(though that gives me a different error description).
Try:

If IsNull([pbornday]) Then
[pname].backcolor = vbRed
[pname].forecolor = vbYellow
Else
[pname].backcolor = vbWhite
[pname].forecolor = vbBlack
End If


--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.


Robin Chapple said:
Fred,

The below code will work for all versions.
In the Form's Current event, as well as in the [pbornday] AfterUpdate
event (change the colors as desired):

If IsNull([pbornday] Then
[pname].backcolor = vbRed
[pname].forecolor = vbYellow
Else
[pname].backcolor = vbWhite
[pname].forecolor = vbBlack
End If

As predicted I tried this and had this error message:

"" Run time error 438
Object does not support this property or method ""

Robin
 
F

Fredg

Robbin,
The Conditional Formatting only changes formatting
when the condition is met.
Did you set the Default Formatting for when the condition is NOT met?

I just ran a test of your expression...
IsNull([spbornday]) And ([spname]) Is Not Null
If a name is entered in the [spname] field AND the [spbornday] is null,
the spname field changes color.
Enter a [spbornday] and the color changes back to the default.
or...
Remove the [spname], and the color changes to the default.

--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.


Robin Chapple said:
Fred,

Thanks. I was unaware of the conditional formatting option. That will
get used in the future.

The scheme works well but I need to ignore the colour change if there
is not a partner name mentioned.

I have tried this and other variations without success:

IsNull([spbornday]) And ([spname]) Is Not Null

The field names are different from my original question.

Thanks,

Robin

Robbin,

You can do this in the [pname] control's Conditional Formatting property
if you are using Access 2000 or later:
Select the [pname] control.
click Format + Conditonal formatting.
Set the Condition1 drop-down to
Expression Is
In the text box along side this drop-down, write:
IsNull([pbornday])

Select the colors.
Save the change.

The below code will work for all versions.
In the Form's Current event, as well as in the [pbornday] AfterUpdate
event (change the colors as desired):

If IsNull([pbornday] Then
[pname].backcolor = vbRed
[pname].forecolor = vbYellow
Else
[pname].backcolor = vbWhite
[pname].forecolor = vbBlack
End If


Robin said:
I have a membership database where the Partner name is recorded if
there is a partner. We also record partner birthday so that we can
send birthday greetings.

Some of our members record partner name but forget to enter the
birthday.

On the form I need to change the background colour of the [pname]
field if the [pbornday] field is blank probably using the form
OnCurrent event.

Is this possible?

Thanks,

Robin Chapple
 

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