Hello All,
Is there a simpler way to count text boxes with data in them when the
4 text boxes are in the header of a form?
I've written the code below and it works.
,----- [ Count text box with data & it works ]
| Private Sub cmdBtnQueryCoName_Click()
| 'declare variables
| Dim intCountTxtBoxWithData As Integer
|
| intCountTxtBoxWithData = 0
|
| If IsNull(Form_frmSelectCoName.txtCoNameSrch1) Then
| 'do nothing
| Else
| intCountTxtBoxWithData = intCountTxtBoxWithData + 1
| End If
|
| If IsNull(Form_frmSelectCoName.txtCoNameSrch2) Then
| 'do nothing
| Else
| intCountTxtBoxWithData = intCountTxtBoxWithData + 1
| End If
|
| If IsNull(Form_frmSelectCoName.txtCoNameSrch3) Then
| 'do nothing
| Else
| intCountTxtBoxWithData = intCountTxtBoxWithData + 1
| End If
|
| If IsNull(Form_frmSelectCoName.txtCoNameSrch4) Then
| 'do nothing
| Else
| intCountTxtBoxWithData = intCountTxtBoxWithData + 1
| End If
|
| Debug.Print intCountTxtBoxWithData
|
| End Sub
`-----
I'd rather be able to do with a loop. I believe it could be done with
the forms collection, but how would I code the value in for the
following line?
If Not IsNull(Value) Then IsBlank=False
Or 'Form_frmSelectCoName.txtCoNameSrch#' would have to replaced with
appropriate reference for the value in the respective text box on in
the loop of the forms collection for the code below.
,----- [ Forms Control Loop ]
| Dim ctl As Control
| Dim IsBlank As Boolean
| Dim intCountTxtBoxWithData As Integer
|
| intCountTxtBoxWithData = 0
|
| For Each ctl In Me.Controls
| IsBlank = True
| If ctl.ControlType = acTextBox Then
| If Not IsNull(Value) Then IsBlank=False
| End If
| If IsBlank = False Then intCountTxtBoxWithData =
intCountTxtBoxWithData + 1
| Next
|
| Debug.Print intCountTxtBoxWithData
`-----
Just thinking out loud. Your ideals would be appreciated. Thanks!
--
Regards,
Greg Strong