none
Varchar value but first three values must be numeric RRS feed

  • Question

  • I have a field called gf1 which is a varchar(6) value.  The first 3 values must be numeric e.g. 123ABC, 345FGD.

    I want to build a rule using an if statement in vba to display a message if one of the first 3 values is not numeric.  Please can somebody help.

    Monday, October 26, 2015 8:37 PM

Answers

  • You can test using Left() and IsNumeric()

    Private Sub Form_Current()
        If IsNumeric(Left(Me.txtCompany, 3)) = False Then
            Me.txtCompany.ForeColor = vbRed
        Else: Me.txtCompany.ForeColor = vbWhite
        End If
        
    End Sub
    


    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    Monday, October 26, 2015 9:06 PM
  • If gf1 is receiving data through a form text box control,

    you can set the control’s “Validation Rule” to: Like "###*"
    And you can have a “Validation Text” with:  Must begin with three numbers.
    These Validation properties are found in the “Data” tab of the selected control’s Property Sheet.


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.


    Tuesday, October 27, 2015 3:28 PM

All replies

  • You can test using Left() and IsNumeric()

    Private Sub Form_Current()
        If IsNumeric(Left(Me.txtCompany, 3)) = False Then
            Me.txtCompany.ForeColor = vbRed
        Else: Me.txtCompany.ForeColor = vbWhite
        End If
        
    End Sub
    


    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    Monday, October 26, 2015 9:06 PM
  • If gf1 is receiving data through a form text box control,

    you can set the control’s “Validation Rule” to: Like "###*"
    And you can have a “Validation Text” with:  Must begin with three numbers.
    These Validation properties are found in the “Data” tab of the selected control’s Property Sheet.


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.


    Tuesday, October 27, 2015 3:28 PM