Results 1 to 2 of 2

Thread: VBA (Access) & Postcodes

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Wales
    Posts
    41

    VBA (Access) & Postcodes

    Hi, Can anyone help please.

    In access 97, Customer table : Name: Address: PostCode: TelNo: Etc.

    Within the UK any one PostCode can have 4 different ways of being presented, I.E

    Examples.

    AB10 1AB
    AB101AB

    Some PostCodes areas have only 1 number at begining,

    AB1 1AB
    AB11AB

    All 4 are correct, but when exported for a courier company to use the Postcode format is not allways correct to what they want.

    Can I Use code to select different InputMasks for each PostCode, This allowing any user to type however they want into that field but the end result is what is required. Below is whats accepted.

    AB10 1AB Correct
    AB101AB Should be AB10 1AB
    AB1 1AB Correct
    AB11AB should be AB1 1AB.

    Code i'm playing with is:

    Private Sub Post_Code_AfterUpdate()

    Trim (Me.Post_Code) 'Remove spaces start/end (not working)

    If Len(Me.Post_Code) = 7 Or Len(Me.Post_Code) = 8 Then
    Me.Post_Code.InputMask = ">LL00 0LL;;_"
    Else
    Me.Post_Code.InputMask = ">>LL0 0LL;;_"
    End If
    End Sub

    HELP Please!!!


  2. #2
    Fanatic Member
    Join Date
    Aug 2001
    Location
    Connecticut
    Posts
    855
    Input masks don't format (only in appearance) the underlying string if the string is ALREADY entered.
    But try this exercise as a workaround:
    Code:
    Private Sub Text1_Enter()
    Me.Text1.Text = ""
    ' # means space or digit. 
    'sets it at a length of 7 to start.
    'If you choose not to preset a mask, then you'll 
    'need to format multiple cases after entry.
    Me.Text8.InputMask = ">LL0#0LL;;_"
    
    End Sub
    
    Private Sub Text1_Exit(Cancel As Integer)
    Dim s As String
    s = Trim(Me.Text1.Text)
    
    If Mid(s, 4, 1) <> " " Then 
      'this makes it appear formatted in the textbox 
      Me.Text1.InputMask = ">LL00 0LL;;_"
      'do manual formatting
      s = Left(s, 4) & " " & Right(s, 3)
    
    Else
      'already formatted as entered.
    End If
    
    MsgBox Len(s)
    MsgBox s
    End Sub
    VB 6.0, Access, Sql server, Asp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width