473,473 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Simpler way to count text box with Data / Loop on controls?

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
Nov 13 '05 #1
2 2021
Greg Strong wrote:
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!


I'd go for
IsBlank = IsNull(ctl.Value)

Alternatively you could do without the IsBlank variable and go straight for:

intCntTxtBoxWith = intCntTxtBoxWith + abs(not isnull(ctl.value))

--
This sig left intentionally blank
Nov 13 '05 #2
On Mon, 14 Mar 2005 02:31:17 +0000, Trevor Best <no****@besty.org.uk> wrote:
IsNull(ctl.Value)


Thanks!

--
Regards,

Greg Strong
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
5
by: Alex Nitulescu | last post by:
Hi. Because I'm a beginner in creating controls, I spent more than two *&^#$ hours to create this "login" as a custom control and to make it work properly: ...
6
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
8
by: novus | last post by:
Hi, In ASP.net 2.0 I make a control which add the same controls dynamically. In the oninit event I add the controls to the controls collection. After that the loadviewstate event fills in the...
2
by: rn5a | last post by:
A SQL Server 2005 stored procedure expects a parameter 'UserID' depending upon which it retrieves the no. of records & OrderIDs corresponding to the 'UserID' from a DB table (note that OrderID &...
3
by: Chad Scharf | last post by:
Ok, as silly as it may sound, I have a situation where I am creating a CompositeControl in ASP.NET 2.0, C#. I have the following code in the CreateChildControls() method that build the control's...
9
by: NvrBst | last post by:
Whats the best way to count the lines? I'm using the following code at the moment: public long GetNumberOfLines(string fileName) { int buffSize = 65536; int streamSize = 65536; long...
5
by: jehugaleahsa | last post by:
Hello: I am sure this question comes up a lot. I need to disable the controls on my Windows forms so that when the BindingSource is empty some the controls bound to it will be disabled. This...
11
by: jwessner | last post by:
I have a form (Form1) which contains basic Project data and a subform listing the personnel assigned to the Project as a continuous form. Selecting a person on that project and clicking on a command...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.