changing font weight based on field value?

  • Thread starter Thread starter R
  • Start date Start date
R

R

I have a report that prints a test stored in the database. My underlying
table has a column for each:

question_text
possible_answer_1
possible_answer_2
possible_answer_3
possible_answer_4
correct_answer

"correct_answer" is a number between 1 and 4, indicating which possible
answer is the correct one.

My report lists the question, the the four possible answers below. I would
like to check the value of "correct_answer", and then make the correct
answer bold (while the others are all normal weight) in my report. Is this
possible? If yes, how?!

For example:

Question: The sky is _____.
1. purple
2. green
3. blue <-- this field would appear bold because it is correct
4. yellow

(value of "correct_answer" in this case is 3)

Thanks in advance for any help.
 
R said:
I have a report that prints a test stored in the database. My underlying
table has a column for each:

question_text
possible_answer_1
possible_answer_2
possible_answer_3
possible_answer_4
correct_answer

"correct_answer" is a number between 1 and 4, indicating which possible
answer is the correct one.

My report lists the question, the the four possible answers below. I would
like to check the value of "correct_answer", and then make the correct
answer bold (while the others are all normal weight) in my report. Is this
possible? If yes, how?!

For example:

Question: The sky is _____.
1. purple
2. green
3. blue <-- this field would appear bold because it is correct
4. yellow

(value of "correct_answer" in this case is 3)


If you're using A2K+, you can use Conditional Formatting to
do this.

In all versions you can use VBA code in the detail section's
Format event:

Me.txtpossible_answer_1.FontBold = (Me.txtcorrect_answer=1)
Me.txtpossible_answer_2.FontBold = (Me.txtcorrect_answer=2)
Me.txtpossible_answer_3.FontBold = (Me.txtcorrect_answer=3)
Me.txtpossible_answer_4.FontBold = (Me.txtcorrect_answer=4)

where txtwhatever is the name of the textbox bound to the
whatever field.
 
Thanks! But no solution for Access 97, eh?

Marshall Barton said:
If you're using A2K+, you can use Conditional Formatting to
do this.

In all versions you can use VBA code in the detail section's
Format event:

Me.txtpossible_answer_1.FontBold = (Me.txtcorrect_answer=1)
Me.txtpossible_answer_2.FontBold = (Me.txtcorrect_answer=2)
Me.txtpossible_answer_3.FontBold = (Me.txtcorrect_answer=3)
Me.txtpossible_answer_4.FontBold = (Me.txtcorrect_answer=4)

where txtwhatever is the name of the textbox bound to the
whatever field.
 
R said:
Thanks! But no solution for Access 97, eh?

Maybe you didn't scroll my message down far enough to see
the code you can use to do this in A97?
--
Marsh
MVP [MS Access]


 
DUH - Read it, but the "in all versions" part immediately left my brain...
Thanks Marshall!
 
Hoping you're still there and get this ....

Per your reply, I included the following as the On Format event:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.fldResponse1.FontBold = (Me.fldAnswer = 1)
Me.fldResponse2.FontBold = (Me.fldAnswer = 2)
Me.fldResponse3.FontBold = (Me.fldAnswer = 3)
Me.fldResponse4.FontBold = (Me.fldAnswer = 4)
End Sub

Works beautifully when there are questions in my database - but in the event
there aren't any, I'm getting an error. I'm guessing it's because fldAnswer
is blank. What can I include so that if fldAnswer is blank, the report
won't crash - just opens with nothing in it??

Thanks in advance...
 
R said:
Per your reply, I included the following as the On Format event:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.fldResponse1.FontBold = (Me.fldAnswer = 1)
Me.fldResponse2.FontBold = (Me.fldAnswer = 2)
Me.fldResponse3.FontBold = (Me.fldAnswer = 3)
Me.fldResponse4.FontBold = (Me.fldAnswer = 4)
End Sub

Works beautifully when there are questions in my database - but in the event
there aren't any, I'm getting an error. I'm guessing it's because fldAnswer
is blank. What can I include so that if fldAnswer is blank, the report
won't crash - just opens with nothing in it??

I don't now what you mean when you say there aren't any
questions, or how the report could be totally blank???


If fldAnswer is Null, you could use this:

Me.fldResponse1.FontBold = (Nz(Me.fldAnswer, 0) = 1)
. . .
 
When the database is first distributed, it's blank. The user then enters
the questions and answers that will be used in the application. In the
event the user prints the report before there are any questions, I want the
report to still be able to print. Currently, if the questions and answers
are all blank (there are no records at all) I get:

Run-time error '2427'
You entered an express that has no value.

Using your newly suggested code (Me.fldResponse1.FontBold =
(Nz(Me.fldAnswer, 0) = 1) I get:

Run-time error '-2147352567 (80020009)'
You entered an expression that has no value.

?? Any thoughts?
 
R said:
When the database is first distributed, it's blank. The user then enters
the questions and answers that will be used in the application. In the
event the user prints the report before there are any questions, I want the
report to still be able to print. Currently, if the questions and answers
are all blank (there are no records at all) I get:

Run-time error '2427'
You entered an express that has no value.

You'll have to isolate the expression that's causing the
error. Does the error message box have a Debug button?

I still don't understand what this "blank" is, why not give
the users a blank sheet of paper?

Using your newly suggested code (Me.fldResponse1.FontBold =
(Nz(Me.fldAnswer, 0) = 1) I get:

Run-time error '-2147352567 (80020009)'
You entered an expression that has no value.

That's starting to sound ominous. Where did you put that
expression?
 
When I say "blank", I mean that the table where the questions & answers go
is empty - there are no records.

I updated the Event Procedure for the Detail section's On Format property to
be:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.fldResponse1.FontBold = (Nz(Me.fldAnswer, 0) = 1)
Me.fldResponse2.FontBold = (Nz(Me.fldAnswer, 0) = 2)
Me.fldResponse3.FontBold = (Nz(Me.fldAnswer, 0) = 3)
Me.fldResponse4.FontBold = (Nz(Me.fldAnswer, 0) = 4)
End Sub

That's what's causing the "ominous" error message - and clicking debug in
both cases has the first Me.fldResponse line highlighted.

I'm certain it's that there are no records at all in the underlying query.
If there is no way to suppress the error and just display a blank report
page (only showing the header), I can probably deal with it another way (put
up a message that the report is empty), but I'd rather print a blank page if
it's doable.
 
R said:
When I say "blank", I mean that the table where the questions & answers go
is empty - there are no records.

I updated the Event Procedure for the Detail section's On Format property to
be:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.fldResponse1.FontBold = (Nz(Me.fldAnswer, 0) = 1)
Me.fldResponse2.FontBold = (Nz(Me.fldAnswer, 0) = 2)
Me.fldResponse3.FontBold = (Nz(Me.fldAnswer, 0) = 3)
Me.fldResponse4.FontBold = (Nz(Me.fldAnswer, 0) = 4)
End Sub

That's what's causing the "ominous" error message - and clicking debug in
both cases has the first Me.fldResponse line highlighted.

I'm certain it's that there are no records at all in the underlying query.
If there is no way to suppress the error and just display a blank report
page (only showing the header), I can probably deal with it another way (put
up a message that the report is empty), but I'd rather print a blank page if
it's doable.

OK, now I understand. You can use the report's NoData event
to tell when there are no records in the report. I think
you should set a module level boolean variable in the
NoData event and test it in any section that you want to
handle differently from usual. For example:

Private bolEmptyReport As Boolean

Private Sub Report_NoData(Cancel As Integer)
bolEmptyReport = True
End Sub

Private Sub Detail_Format(Cancel As Integer, FormatCount As
Integer)

If bolEmptyReport Then Exit Sub
Me.fldResponse1.FontBold = (Nz(Me.fldAnswer, 0) = 1)
 
Hm, I get the concept, but not knowing much about writing code yet (I know,
shocker, huh? : }) I'm not sure what to put where. I know where the On No
Data event is, but I'm not sure what goes in there, and what I need to
change in the Detail's On Format event to make it all work together.

Sorry... : ( ...but thanks, and that should be it from me for a while!
 
R said:
Hm, I get the concept, but not knowing much about writing code yet (I know,
shocker, huh? : }) I'm not sure what to put where. I know where the On No
Data event is, but I'm not sure what goes in there, and what I need to
change in the Detail's On Format event to make it all work together.


I gave a speciific code example that I think will take care
of what you need (at least as much as you've told me about).

As far as the event goes, let's be absolutely clear about
terminology here. OnNoData is a property in the report's
property sheet, this should have [Event Procedure] in it
(including the square brackets). The NoDate event procedure
should look like the code I posted below. Note that I added
an If statement to the Detail_Format event procedure to exit
the procedure so the code that was giving you an error
doesn't try to execute when there is no data.
--
Marsh
MVP [MS Access]


 
I think I'm still doing something wrong... if my table is empty, then the
report would be empty, and my bolEmptyReport = True doesn't seem to be
getting acknowledged by the If bolEmptyReport Then Exit Sub statement.

Here's what I have:

On Format event -- Format - Detail:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If bolEmptyReport Then Exit Sub
Me.fldResponse1.FontBold = (Me.fldAnswer = "1")
Me.fldResponse2.FontBold = (Me.fldAnswer = "2")
Me.fldResponse3.FontBold = (Me.fldAnswer = "3")
Me.fldResponse4.FontBold = (Me.fldAnswer = "4")
End Sub

On No Data event -- Report - NoData:
Private Sub Report_NoData(Cancel As Integer)
bolEmptyReport = True
End Sub

Am I missing something?? I'm sorry!!!! : ( But thanks!

Basically, I get run-time error '2427', you entered an expression that has
no value. Debug has the Me.fldResponse1....line highlighted.



Marshall Barton said:
R said:
Hm, I get the concept, but not knowing much about writing code yet (I know,
shocker, huh? : }) I'm not sure what to put where. I know where the On No
Data event is, but I'm not sure what goes in there, and what I need to
change in the Detail's On Format event to make it all work together.


I gave a speciific code example that I think will take care
of what you need (at least as much as you've told me about).

As far as the event goes, let's be absolutely clear about
terminology here. OnNoData is a property in the report's
property sheet, this should have [Event Procedure] in it
(including the square brackets). The NoDate event procedure
should look like the code I posted below. Note that I added
an If statement to the Detail_Format event procedure to exit
the procedure so the code that was giving you an error
doesn't try to execute when there is no data.
--
Marsh
MVP [MS Access]


 
R said:
I think I'm still doing something wrong... if my table is empty, then the
report would be empty, and my bolEmptyReport = True doesn't seem to be
getting acknowledged by the If bolEmptyReport Then Exit Sub statement.

Here's what I have:

On Format event -- Format - Detail:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If bolEmptyReport Then Exit Sub
Me.fldResponse1.FontBold = (Me.fldAnswer = "1")
Me.fldResponse2.FontBold = (Me.fldAnswer = "2")
Me.fldResponse3.FontBold = (Me.fldAnswer = "3")
Me.fldResponse4.FontBold = (Me.fldAnswer = "4")
End Sub

On No Data event -- Report - NoData:
Private Sub Report_NoData(Cancel As Integer)
bolEmptyReport = True
End Sub

Am I missing something?? I'm sorry!!!! : ( But thanks!

I don't see the line of declaration at the top of the module
(before any procedure):
Private bolEmptyReport As Boolean



"Marshall Barton" wrote
R said:
Hm, I get the concept, but not knowing much about writing code yet (I know,
shocker, huh? : }) I'm not sure what to put where. I know where the On No
Data event is, but I'm not sure what goes in there, and what I need to
change in the Detail's On Format event to make it all work together.

"Marshall Barton" wrote
I gave a speciific code example that I think will take care
of what you need (at least as much as you've told me about).

As far as the event goes, let's be absolutely clear about
terminology here. OnNoData is a property in the report's
property sheet, this should have [Event Procedure] in it
(including the square brackets). The NoDate event procedure
should look like the code I posted below. Note that I added
an If statement to the Detail_Format event procedure to exit
the procedure so the code that was giving you an error
doesn't try to execute when there is no data.


"Marshall Barton" wrote
OK, now I understand. You can use the report's NoData event
to tell when there are no records in the report. I think
you should set a module level boolean variable in the
NoData event and test it in any section that you want to
handle differently from usual. For example:

Private bolEmptyReport As Boolean

Private Sub Report_NoData(Cancel As Integer)
bolEmptyReport = True
End Sub

Private Sub Detail_Format(Cancel As Integer, FormatCount As
Integer)

If bolEmptyReport Then Exit Sub
Me.fldResponse1.FontBold = (Nz(Me.fldAnswer, 0) = 1)
. . .
 
Back
Top