Clicking & Updating controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am reposting this question.
I think it should be easy but I'm stuck...!

i have created a quiz form for users to test their knowledge of different
features in an Access database. Each question has 4 parts:
a) label for question e.g. lblQ1
b) unbound text box fo user to enter answer e.g. txtQ1
c) list box with correct answer (txtA1) based on SQL query
e.g. SELECT Max(PupilData.DeMerits) AS MaxOfDeMerits FROM PupilData;
d) text box (txtR1) which shows Correct or Wrong by comparing txtQ1 & txtA1
=IIf([txtQ1]=[txtA1],"Correct","Wrong")
I thought this should work without problems.

Control txtA1 should always be hidden.
Control txtR1 appears when txtQ1 is updated.

Code used is:

Private Sub txtQ1_AfterUpdate()
Me.txtR1.Visible = True
Me.txtA1.Requery
End Sub

The problem is that txtR1 shows "Wrong" even when txtQ1 & txtA1 are
identical until I click the control txtA1 when it updates correctly.
This means I cannot hide the answer txtA1 as planned!

However, once i have clicked in txtA1 once, the response txtR1 then updates
correctly if new answers are entered in txtQ1.

I have tried requerying txtA1 as the form loads but this doesn't have any
effect
How can I add code so that the control is automatically clicked ...or change
the code to have the desired result?

I'm sure there is a very obvious solution to this but I'm stuck at present
Any ideas?
 
ridders said:
I am reposting this question.
I think it should be easy but I'm stuck...!

i have created a quiz form for users to test their knowledge of different
features in an Access database. Each question has 4 parts:
a) label for question e.g. lblQ1
b) unbound text box fo user to enter answer e.g. txtQ1
c) list box with correct answer (txtA1) based on SQL query
e.g. SELECT Max(PupilData.DeMerits) AS MaxOfDeMerits FROM PupilData;
d) text box (txtR1) which shows Correct or Wrong by comparing txtQ1 &
txtA1
=IIf([txtQ1]=[txtA1],"Correct","Wrong")
I thought this should work without problems.

Control txtA1 should always be hidden.
Control txtR1 appears when txtQ1 is updated.

Code used is:

Private Sub txtQ1_AfterUpdate()
Me.txtR1.Visible = True
Me.txtA1.Requery
End Sub

The problem is that txtR1 shows "Wrong" even when txtQ1 & txtA1 are
identical until I click the control txtA1 when it updates correctly.
This means I cannot hide the answer txtA1 as planned!

However, once i have clicked in txtA1 once, the response txtR1 then
updates
correctly if new answers are entered in txtQ1.

I have tried requerying txtA1 as the form loads but this doesn't have any
effect
How can I add code so that the control is automatically clicked ...or
change
the code to have the desired result?

I'm sure there is a very obvious solution to this but I'm stuck at present
Any ideas?

Something you might try is setting the values of txtA1 and txtR1 directly in
the AfterUpdate event of txtQ1:

Me.txtA1 = DMax("DeMerits","PupilData")
Me.txtR1 = IIf(Me.txtA1 = Me.txtQ1, "Correct", Wrong")

rather than in their ControlSources.

Carl Rapson
 
storrboy said:
Have you tried requerying txtR1?

Thanks for this - it partly did the job!

I changed the code for txtQ1_AfterUpdate to:

Private Sub txtQ1_AfterUpdate ()
Me.txtR1.Requery
Me.txtR1.Visible = true
Me.txtQ2.SetFocus

End Sub

On its own, this didn't fix it. However I changed txtA1 from a list box to a
text box and amended its control source accordingly.
It then worked fine for the first 4 questions!

However for question 5 onwards, the response text box e.g. txtR5 stays hidden.
The code is identical to that for earlier questions but it just won't show.

Again I'm stuck.
Any more ideas?
 
Thanks Carl but this didn't help.

Carl Rapson said:
ridders said:
I am reposting this question.
I think it should be easy but I'm stuck...!

i have created a quiz form for users to test their knowledge of different
features in an Access database. Each question has 4 parts:
a) label for question e.g. lblQ1
b) unbound text box fo user to enter answer e.g. txtQ1
c) list box with correct answer (txtA1) based on SQL query
e.g. SELECT Max(PupilData.DeMerits) AS MaxOfDeMerits FROM PupilData;
d) text box (txtR1) which shows Correct or Wrong by comparing txtQ1 &
txtA1
=IIf([txtQ1]=[txtA1],"Correct","Wrong")
I thought this should work without problems.

Control txtA1 should always be hidden.
Control txtR1 appears when txtQ1 is updated.

Code used is:

Private Sub txtQ1_AfterUpdate()
Me.txtR1.Visible = True
Me.txtA1.Requery
End Sub

The problem is that txtR1 shows "Wrong" even when txtQ1 & txtA1 are
identical until I click the control txtA1 when it updates correctly.
This means I cannot hide the answer txtA1 as planned!

However, once i have clicked in txtA1 once, the response txtR1 then
updates
correctly if new answers are entered in txtQ1.

I have tried requerying txtA1 as the form loads but this doesn't have any
effect
How can I add code so that the control is automatically clicked ...or
change
the code to have the desired result?

I'm sure there is a very obvious solution to this but I'm stuck at present
Any ideas?

Something you might try is setting the values of txtA1 and txtR1 directly in
the AfterUpdate event of txtQ1:

Me.txtA1 = DMax("DeMerits","PupilData")
Me.txtR1 = IIf(Me.txtA1 = Me.txtQ1, "Correct", Wrong")

rather than in their ControlSources.

Carl Rapson
 
Back
Top