Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Problems validating data in forms

Discussion in 'Information Technology' started by Edgar Cohen, Jul 28, 2006.

  1. Edgar Cohen

    Edgar Cohen
    Expand Collapse
    Guest

    I am new to the VBA world. I have a form that I am trying to validate
    the fields on. They are either text boxes or combo boxes. I have a
    custom function that is called when the user clicks a command button. I
    cannot test any of these fields for no user input or null. None of these
    work:

    If (Me.txtProductCode = Null) Then
    ' some code here
    End if

    or

    If Len (Me.txtProductCode) = Null Then
    ' some code here
    End if
    or

    If Len(Me.txtProductCode) = 0 Then
    ' some code here
    End if

    If IsNull(Me.txtProductCode) = True Then
    ' some code here
    End if

    I have tried to use the expression builder but it is very confusing for
    me. I'd rather do this in VB code. So, how do you check the contents of
    form fields in VB? Where is there some very good examples of this? Thanks

    enc0hen@comcast.net
     
  2. Loading...

    Similar Threads Forum Date
    Sikh News Sikhs Face Problems While Carrying Kirpans In Khyber-Pakhtunkhwa - SikhSiyasat.Net Breaking News Jul 29, 2016
    "Dasam" Granth - A Look At The Core Problems Dasam Granth Oct 21, 2015
    Problems In Life Sikh Sikhi Sikhism Apr 13, 2015
    Muslim Girl-Sikh Boy Marriage Problems- Please Help! Love & Marriage Oct 12, 2012
    Problems with Sikh Historiography-prof Jagdish Singh Sikh Video Aug 31, 2012

  3. Rick Brandt

    Rick Brandt
    Expand Collapse
    Guest

    Edgar Cohen wrote:
    > I am new to the VBA world. I have a form that I am trying to validate
    > the fields on. They are either text boxes or combo boxes. I have a
    > custom function that is called when the user clicks a command button.
    > I cannot test any of these fields for no user input or null. None of
    > these work:
    >
    > If (Me.txtProductCode = Null) Then
    > ' some code here
    > End if
    >
    > or
    >
    > If Len (Me.txtProductCode) = Null Then
    > ' some code here
    > End if
    > or
    >
    > If Len(Me.txtProductCode) = 0 Then
    > ' some code here
    > End if
    >
    > If IsNull(Me.txtProductCode) = True Then
    > ' some code here
    > End if


    This last one should work. Nothing is ever "equal" to null which is why the
    other expressions you tried don't work. IsNull() though should do exactly what
    you want (providing that an empty control is actually Null and not a zero length
    string ("").

    > I have tried to use the expression builder but it is very confusing
    > for me. I'd rather do this in VB code. So, how do you check the
    > contents of form fields in VB? Where is there some very good examples
    > of this? Thanks


    Something that covers both Nulls and zero length strings is a test like..

    If Len(Me!ControlName & vbNullString) = 0 Then...


    --
    Rick Brandt, Microsoft Access MVP
    Email (as appropriate) to...
    RBrandt at Hunter dot com
     
  4. Larry Linson

    Larry Linson
    Expand Collapse
    Guest

    Null is, by definition, an "unknown value" that cannot be "equal" to
    anything else, even the constant Null or another null value. If testing for
    length, it appears you want to detect either a Null or a Null (Zero-Length)
    String, so that should be

    If Len(Me.txtProductCode & "") = 0 Then

    If the user has entered nothing into the Control, I don't know why

    > If IsNull(Me.txtProductCode) = True Then
    > ' some code here
    > End if


    would not test True.

    Larry Linson
    Microsoft Access MVP
     

Share This Page