Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculating letters in text boxes 1

Status
Not open for further replies.

rene1000

IS-IT--Management
Apr 9, 2002
89
NL
I have created a form with 372 textboxes which can each contain 1 letter. I want to count in how many of these textboxes the letter (for instance) V is entered and show the result in another textbox on the form. Can this be done ?
 
Certainly it's possible, but first...

Do you need to differentiate between upper and lower case?

Ken S.
 
no, not really. I want to make the form that way that only uppercase characters can be entered.
 
Okay, here goes...

Code:
Dim strLetter1 As String
Dim strLetter2 As String
Dim ctrl As Control
Dim i As Integer

i = 0
strLetter1 = UCase(InputBox("Enter a search letter (1 letter only!)"))

If Len(strLetter1) <> 1 Then
    MsgBox &quot;Doh!  You entered the wrong number of characters!  Goodbye...&quot;
    Exit Sub
End If

For Each ctrl In Me.Controls
    If (ctrl.ControlType = acTextBox) _
    And (ctrl.Name <> &quot;txtSearchCount&quot;) _
    And Not IsNull(ctrl) Then
        strLetter2 = UCase(ctrl.Value)
        If strLetter2 = strLetter1 Then
            i = i + 1
        End If
    End If
Next ctrl
Me!txtSearchCount = i

Make an event procedure for the On Click event of a command button. When executed, the code will prompt the user for the letter to search on, then will cycle through all the controls on the form and will count all the ones that match the user's input, then will put that value in a textbox on the form. Replace &quot;txtSearchCount&quot; with the name of the field on your form that will hold the count result. That should get you started...

Ken S.
 
Thank you very much Ken, it works great !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top