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!

Can I get my form to display the no. of text boxes with data in?

Status
Not open for further replies.

vacant

Technical User
Aug 5, 2001
35
GB
I am very new to Access, and am creating a database at work of doctors, dentists, etc.
The form I have made for amendments\deletions displays one record at a time, and it includes a text box for the main partner, with a further 9 text boxes for any remaining partners at the surgery. A further property of this form is the total_number_of_partners at that particular surgery which at the moment I input via a list box.
It would be really nice if I could get Access to calculate and update this field automatically. Is there a (easy) way of doing this, please?

cheers :)
TT
 
it depends on how you name your fields

this example uses 10 textboxes each starting with txtPartner and are numbered 1 to 10, it also uses a textbox named txtTotal to store the values. The textboxes are bound to fields in the Form's Recordset. Use the Form's BeforeUpdate Event to check how many textboxes are filled in.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim i As Integer, x As Integer
Dim strFld As String
For i = 1 To 10
strFld = "txtPartner" & i
If Me(strFld) <> &quot;&quot; And Me(strFld) <> &quot; &quot; Then
x = x + 1
End If
Next i
txtTotal = x
End Sub

PaulF
 
Could do a similar thing using the tag property and looping round all the controls on the form looking. This would work irrespective on the name of the control but would require more complex code.

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top