Hey everyone!
I am having a little trouble with an addition flash card userform that I am working on. Everything was working exactly as I intended until I tried to implement a keyup event. My intention was to remove the need to press return twice (once for entering answer in text box, and once again to proceed to the next question). Now, with the keyup event, I am able to enter the answer and go to the next question, however the focus is then placed on the "Next" command button. I have tried putting "me.txtSolution.SetFocus" throughout my code to no avail. Any thoughts would be greatly appreciated.
Thank you for your help! This is what I have so far:
Private Sub btnNext_Click()
Dim n1, n2 As Integer
If IsNumeric(txtSolution.Value) Then
lblAddend1.ForeColor = vbBlack
lblAddend2.ForeColor = vbBlack
If Int(lblAddend1.Caption) + Int(lblAddend2.Caption) <> Int(txtSolution.Value) Then
lblAddend1.ForeColor = vbRed
lblAddend2.ForeColor = vbRed
txtSolution.Value = ""
Else
txtSolution.Value = ""
Dim high, low As Double
low = Worksheets("Data").Range("C4").Value
high = Worksheets("Data").Range("C5").Value
low2 = Worksheets("Data").Range("F4").Value
high2 = Worksheets("Data").Range("F5").Value
n1 = Int((high - low + 1) * Rnd() + low)
n2 = Int((high2 - low2 + 1) * Rnd() + low2)
lblAddend1.Caption = n1
lblAddend2.Caption = n2
End If
Else
txtSolution.Value = ""
End If
Me.txtSolution.SetFocus
End Sub
Private Sub txtSolution_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then
Call btnNext_Click
End If
End Sub
Bookmarks