Re: Counting specific words in Strings
The first question I would have HyperX is do you want to do this just with forumulas on the worksheet or with a macro?
Re: Counting specific words in Strings
The first question I would have HyperX is do you want to do this just with forumulas on the worksheet or with a macro?
Re: set Focus Back To Control
This isn't all of the code attached to the form but should be enough for you to get an idea. If not, I can load more:
Private Function AddScore(HoleNum As Integer) As Boolean
'+-----------------------------------------------------------------------------------------------+
'| Dynamically calculate the Score Out every time a value is entered in one of the 9 score out |
'| text boxes. |
'+-----------------------------------------------------------------------------------------------+
Dim lp As Byte
Dim Hole As String
Dim ScoreOut As Integer
Dim ScoreIn As Integer
AddScore = True
Select Case HoleNum
Case Is < 10
Hole = Format(HoleNum, "00")
If Val(fra_Out.Controls("txt_Score" & Hole)) <= 0 Then
fra_Out.Controls("txt_Score" & Hole) = ""
fra_Out.Controls("txt_Score" & Hole).SetFocus
' fra_Out.Controls("txt_score" & Hole).SelStart = 1
Else
ScoreOut = 0
For lp = 1 To 9
Hole = Format(lp, "00")
ScoreOut = ScoreOut + Val(fra_Out.Controls("txt_Score" & Hole))
Next lp
txt_ScoreOut = ScoreOut
End If
Case Is > 9
Hole = Format(HoleNum, "00")
If Val(fra_In.Controls("txt_Score" & Hole)) <= 0 Then
fra_In.Controls("txt_Score" & Hole) = ""
fra_In.Controls("txt_Score" & Hole).SetFocus
Else
ScoreIn = 0
For lp = 10 To 18
Hole = Format(lp, "00")
ScoreIn = ScoreIn + Val(fra_In.Controls("txt_Score" & Hole))
Next lp
txt_ScoreIn = ScoreIn
End If
End Select
End Function
Private Sub txt_Score01_Change()
Call AddScore(1)
End Sub
Private Sub txt_Score02_Change()
Call AddScore(2)
End Sub
Private Sub txt_Score03_Change()
Call AddScore(3)
End Sub
Private Sub txt_Score04_Change()
Call AddScore(4)
End Sub
Private Sub txt_Score05_Change()
Call AddScore(5)
End Sub
Private Sub txt_Score06_Change()
Call AddScore(6)
End Sub
Private Sub txt_Score07_Change()
Call AddScore(7)
End Sub
Private Sub txt_Score08_Change()
Call AddScore(8)
End Sub
Private Sub txt_Score09_Change()
Call AddScore(9)
End Sub
Display More
The txt_Scorexx_Change is the code attached to the text boxes. Again, there are a total of 36 of these on the form.
Thanks for offering to help!
Re: set Focus Back To Control
Hey SuperDave
I was searching for a similar problem and I think your sollution is what I probably need, but (you were waiting).....
I have 36 text boxes on the form. I could not find any way of having one function to handle all of them so I made a separate function and just made the _chage event for each of the 36 txt controls call that function. No problems at this point.
In the main function, I do some simple validation and minor work. If the user entered an invalid value (in this case all of the txt fields must be numeric and single digit), I clear out the control and setfocus back to it.
The problem is that when I run it in debug mode, all works well. When I run it normally, the text field is cleared but the focus will not go back to that text field - since it is max_length=1, it goes to the next field. Any ideas?