Left function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sallyatag
    New Member
    • Sep 2010
    • 1

    Left function

    Hi, I need to take the first letter/letters of a UK postcode and copy it into another field. However, some postcodes are two letters followed by numbers and some are one letter followed by numbers.

    How can I make sure that it copies just the letters only?

    Thanks

    Sally
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    #2
    here you go. Assuming you have two text boxes Text0, Text2. This will loop through the characters in Text0 then display only non-integer characters in Text2 Enjoy!

    Code:
    Dim s, s2 As String
    Dim i As Integer
    
    s = Me.Text0.Value
    
        For i = 1 To Len(s)
            If IsNumeric(Mid(s, i, 1)) = False Then
                s2 = s2 & Mid(s, i, 1)
            End If
    Next i
     
     Me.Text2.Value = s2

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      If this is in a QueryDef then something similar to this can be used :
      Code:
      Left([PCode],IIf(IsNumeric(Mid([PCode],2,1)),1,2))

      Comment

      Working...