Alternate Rows - Change of Text

P

Public Schools

Hello.

I am having trouble writing an If.Then.Else statement and need assistance.

My report is set up as follows:

Question No. Correct Answer Reporting Category Descriptor
1. B 002
Estimation
2. D 006
Geometry
3. C 007
Patterns
4. C 001
Statistics
5. A 003
Algebra
6. C 004
Numbers
etc.

I would like the even numbered/row answers to be:
A=F
B=G
C=H
D=J

The Question No is a text box and is unbound. The Correct Answer field is
[CorrectAnswer].

I've tried the following, but it does not work. Any suggestions?

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If Me.[LineNum] Mod 2 = 0 Then
Me![CorrectAnswer].Text "A" = "A"
Me![CorrectAnswer].Text "B" = "B"
Me![CorrectAnswer].Text "C" = "C"
Me![CorrectAnswer].Text "D" = "D"
Else
Me![CorrectAnswer].Text "A" = "F"
Me![CorrectAnswer].Text "B" = "G"
Me![CorrectAnswer].Text "C" = "H"
Me![CorrectAnswer].Text "D" = "J"
End If


End Sub

Thanks for your time.
 
K

Klatuu

This is what you are after:

If Me.[LineNum] Mod 2 <> 0 Then
Select Case Me![CorrectAnswer]
Case "A"
Me![CorrectAnswer] = "F"
Case "B"
Me![CorrectAnswer] = "G"
Case "C"
Me![CorrectAnswer] = "H"
Case "D"
Me![CorrectAnswer] = "J"
End Select
End If
 
P

Public Schools

Klatuu,

Thank you, thank you, thank you for your reply. Believe it or not, I have
been trying since your posting to get this problem solved. I did as you
instructed, but maybe I am not doing it correctly because it did not work.

Please coach me along. I pasted they code you provided in the Detail
section of the report as an event On Format. I kept receiving an error debug
message, particularly for Me![CorrectAnswer] = "G". Woul you mind assisting
me a little further?

I would like the even numbered lines to change text to F, G, H, or J if
corresponding letters A, B, C, or D is shown. The text box for the line
number is named LineNum and control source is =1. The text box for answer is
named CorrectAnswer and control source is CorrectAnswer. The record source
for the report is a query with a filter for question selected (i.e. Filter is
[Select]=Yes and is on).

I hope this helps. Thanks for your time. I anxiously await assistance.




--
Helping the kids


Klatuu said:
This is what you are after:

If Me.[LineNum] Mod 2 <> 0 Then
Select Case Me![CorrectAnswer]
Case "A"
Me![CorrectAnswer] = "F"
Case "B"
Me![CorrectAnswer] = "G"
Case "C"
Me![CorrectAnswer] = "H"
Case "D"
Me![CorrectAnswer] = "J"
End Select
End If

--
Dave Hargis, Microsoft Access MVP


Public Schools said:
Hello.

I am having trouble writing an If.Then.Else statement and need assistance.

My report is set up as follows:

Question No. Correct Answer Reporting Category Descriptor
1. B 002
Estimation
2. D 006
Geometry
3. C 007
Patterns
4. C 001
Statistics
5. A 003
Algebra
6. C 004
Numbers
etc.

I would like the even numbered/row answers to be:
A=F
B=G
C=H
D=J

The Question No is a text box and is unbound. The Correct Answer field is
[CorrectAnswer].

I've tried the following, but it does not work. Any suggestions?

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If Me.[LineNum] Mod 2 = 0 Then
Me![CorrectAnswer].Text "A" = "A"
Me![CorrectAnswer].Text "B" = "B"
Me![CorrectAnswer].Text "C" = "C"
Me![CorrectAnswer].Text "D" = "D"
Else
Me![CorrectAnswer].Text "A" = "F"
Me![CorrectAnswer].Text "B" = "G"
Me![CorrectAnswer].Text "C" = "H"
Me![CorrectAnswer].Text "D" = "J"
End If


End Sub

Thanks for your time.
 
K

Klatuu

I don't see any obviuos reason it is not working.
Have you tried putting the code in the Detail section's Print event instead
of the format event?

--
Dave Hargis, Microsoft Access MVP


Public Schools said:
Klatuu,

Thank you, thank you, thank you for your reply. Believe it or not, I have
been trying since your posting to get this problem solved. I did as you
instructed, but maybe I am not doing it correctly because it did not work.

Please coach me along. I pasted they code you provided in the Detail
section of the report as an event On Format. I kept receiving an error debug
message, particularly for Me![CorrectAnswer] = "G". Woul you mind assisting
me a little further?

I would like the even numbered lines to change text to F, G, H, or J if
corresponding letters A, B, C, or D is shown. The text box for the line
number is named LineNum and control source is =1. The text box for answer is
named CorrectAnswer and control source is CorrectAnswer. The record source
for the report is a query with a filter for question selected (i.e. Filter is
[Select]=Yes and is on).

I hope this helps. Thanks for your time. I anxiously await assistance.




--
Helping the kids


Klatuu said:
This is what you are after:

If Me.[LineNum] Mod 2 <> 0 Then
Select Case Me![CorrectAnswer]
Case "A"
Me![CorrectAnswer] = "F"
Case "B"
Me![CorrectAnswer] = "G"
Case "C"
Me![CorrectAnswer] = "H"
Case "D"
Me![CorrectAnswer] = "J"
End Select
End If

--
Dave Hargis, Microsoft Access MVP


Public Schools said:
Hello.

I am having trouble writing an If.Then.Else statement and need assistance.

My report is set up as follows:

Question No. Correct Answer Reporting Category Descriptor
1. B 002
Estimation
2. D 006
Geometry
3. C 007
Patterns
4. C 001
Statistics
5. A 003
Algebra
6. C 004
Numbers
etc.

I would like the even numbered/row answers to be:
A=F
B=G
C=H
D=J

The Question No is a text box and is unbound. The Correct Answer field is
[CorrectAnswer].

I've tried the following, but it does not work. Any suggestions?

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If Me.[LineNum] Mod 2 = 0 Then
Me![CorrectAnswer].Text "A" = "A"
Me![CorrectAnswer].Text "B" = "B"
Me![CorrectAnswer].Text "C" = "C"
Me![CorrectAnswer].Text "D" = "D"
Else
Me![CorrectAnswer].Text "A" = "F"
Me![CorrectAnswer].Text "B" = "G"
Me![CorrectAnswer].Text "C" = "H"
Me![CorrectAnswer].Text "D" = "J"
End If


End Sub

Thanks for your time.
 
M

Marshall Barton

Klatuu said:
I don't see any obviuos reason it is not working.
Have you tried putting the code in the Detail section's Print event instead
of the format event?


Dave, IME, that error message usually means that the code
was entered into the OnFormat event property instead of inro
the Format event procedure.
 
P

Public Schools

Thanks, Marsh for explaining it although I have no idea what you two are
talking about. The error I received is:

Run-time error '2448':
you can't assign a value to this object

I press Debug and the following is highlighted in yellow:

Me![CorrectAnswer] = "G"

I hope this helps. Any suggestions?
 
K

Klatuu

Here is what we are talking about.
Your VBA code should be in the form's module but not entered directly into
the text box for the event in the properties dialog box. To enter VBA code
for an event procedure, the proper sequence is click on the small command
button to the right of the event's text box and from the pop up menu, select
Code Builder. The VB editor will open and the code should be put in the
event's Sub.

So, if the properties dialog text box for the event does not say [Event
Procedure], then it is not correct. Delete whatever is in the box and follow
the sequence described above.

Now, given the error you are getting, there is one other posibillity. What
is the control source for the control [Correct Answer]? If you have a
calculation in the control source, that would be the error you get.
--
Dave Hargis, Microsoft Access MVP


Public Schools said:
Thanks, Marsh for explaining it although I have no idea what you two are
talking about. The error I received is:

Run-time error '2448':
you can't assign a value to this object

I press Debug and the following is highlighted in yellow:

Me![CorrectAnswer] = "G"

I hope this helps. Any suggestions?


--
Helping the kids


Klatuu said:
Thanks, Marsh. I didn't really catch that, but it sure would explain it.
 

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