0 Replies - 1999 Views - Last Post: 01 February 2010 - 04:42 AM

#1 raziel_   User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,281
  • Joined: 25-March 09

Check all textboxes in form if they contain numbers only

Posted 01 February 2010 - 04:42 AM

Description: check if all the textboxes in a form contain numbers only. not needed textboxes to be in array
Public Function Chk_If_Numeric(ByRef frm As Form) As Boolean
'the function check from the textboxes in a certain form'
Chk_If_Numeric = True  'set the variable to default value'
    For Each Control In frm 'looping trough the form controls'
        If TypeOf Control Is TextBox Then 'finding only textboxes'
            If Not IsNumeric(Control.Text) Then 'check if contain only numbers'
                Chk_If_Numeric = False 'if one of them is not we return false'
            End If
        End If
    Next
End Function

Private Sub Command1_Click()
'a test button click '
    If Chk_If_Numeric(Form1) Then
        MsgBox "all numbers"
    Else
        MsgBox "not all are numeric"
    End If
End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Check all textboxes in form if they contain numbers only

#2 raziel_   User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,281
  • Joined: 25-March 09

Re: Check all textboxes in form if they contain numbers only

Posted 01 February 2010 - 04:42 AM

Description: check if all the textboxes in a form contain numbers only. not needed textboxes to be in array
Public Function Chk_If_Numeric(ByRef frm As Form) As Boolean
'the function check from the textboxes in a certain form'
Dim cControl As Control

Chk_If_Numeric = True  'set the variable to default value'
    For Each cControl In frm 'looping trough the form controls'
        If TypeOf cControl Is TextBox Then 'finding only textboxes'
            If Not IsNumeric(cControl.Text) Then 'check if contain only numbers'
                Chk_If_Numeric = False 'if one of them is not we return false'
            End If
        End If
    Next
End Function

Private Sub Command1_Click()
'a test button click '
    If Chk_If_Numeric(Form1) Then
        MsgBox "all numbers"
    Else
        MsgBox "not all are numeric"
    End If
End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1