If .....then ....

  • Thread starter Thread starter hyperkink
  • Start date Start date
H

hyperkink

Hi: I have two text boxes, and one depends on the other. There are 3 optios,
when the score is 1, the ranking is 3. If the score is 2, and then the
ranking is 2. If score is 3, then the ranking is 1. I want to use VBA to
write some codes and achieve my goal, could you please help me do an example?
Thank you!
 
If you just want to display the Ranking result in the one textbox based on
what the value is in the Score textbox, you could use this expression as the
ControlSource of the Ranking textbox (no VBA needed at all):

=Switch([ScoreControlName]=1,3,[ScoreControlName]=2,2,[ScoreControlName]=3,1)

If this is not what you want to do, please provide us more details and we
can suggest alternative approaches.
 
Private Sub txtScore_AfterUpdate()

Select Case Me!txtScore
Case 1
Me!txtRanking = 3
Case 2
Me!txtRanking = 2
Case 3
Me!txtRanking = 1
End Select

End Sub

You may find, though, that it's better to have a table that relates the
score to the ranking so that you don't have to hard code them. In that case,
you could join the two tables in a query and use the query as the
RecordSource for your form. Changes to the Score would automatically update
the Ranking.
 
Use the "AfterUpdate" event of Score to add this code
If Me!Score = 1 Then
Me!Ranking = 3
End If
If Me!Score = 2 Then
Me!Ranking = 2
End If
If Me!Score = 3 Then
Me!Ranking = 1
End If
End Sub
 
Hi: Thank you for your help. However, when I build codes for the Ranking text
box, nothings shows on the Ranking textbox. could you tell me why this
happens?
 
Thank you for your help. However, when i build codes for the Ranking textbox,
nothing show up. Could you please tell me why it happens?
 
Not sure what you mean by "build codes for the Ranking text box". Are you
talking about the code I suggested for the AfterUpdate event of the Score
text box, or are you talking about some other code? You do know that you
need to use the names of your text boxes where I've got txtScore and
txtRanking I hope!
 
hyperkink said:
Thank you for your help. However, when i build codes
for the Ranking textbox, nothing show up. Could you
please tell me why it happens?

Possibly, someone could assist you if your question was clear... "i build
codes for the Ranking textbox" does not really explain what you did, nor
where you put the code (I'm presuming that "i build codes" means that you
wrote or created VBA statements, known collectively as 'code' not 'codes',
and placed them somewhere anticipating that they would be executed). But
without knowing what and where, we'd only be guessing.

Larry Linson
Microsoft Office Access MVP
 

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

Back
Top