Input mask change using combobox selection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kaloyan Krumov
    New Member
    • Oct 2010
    • 16

    #1

    Input mask change using combobox selection

    Hello All,
    I have the folowing case.
    table Countries: Country_ID, Country_Name, PHCODE
    In a form i have the folowing fields:
    SCountry
    SCPhone1
    SCPhone2
    I want when i choose a country from the combobox Scountry
    the input mask for SCPhone1 and 2 to load the PHCODE(internat ional phone code) form the Countryes table.
    I'm sure it is easy but i can seems to make it work.
  • Kaloyan Krumov
    New Member
    • Oct 2010
    • 16

    #2
    I used DlookUp but i get error message: 'country code value' runtime error 2471
    Code:
    Private Sub SCCountry_AfterUpdate()
    Dim mask As String
    mask = DLookup("PHCODE", "Countries", "Countryid=" & Me.Form!SCCountry)
    SCPhone1.InputMask = "("& "+" & mask & ")"
    End Sub
    if i remove "Countryid= " & form dlookup it works, but i always returns (+35_)
    wich is the part of the phone code for Bulgaria
    Last edited by Kaloyan Krumov; Oct 25 '10, 11:24 AM. Reason: new developments

    Comment

    • Kaloyan Krumov
      New Member
      • Oct 2010
      • 16

      #3
      done

      Well i did it:
      Syntax error
      Code:
      Dim mask As String
      mask = ""
      mask = DLookup("PHCODE", "Countries", "Countryid='" & Me.SCCountry & "'")
      SCPhone1.InputMask = "(" & "+" & mask & ")"
      Now another problem if the phone code contains 9 or 0 guess how the input mask interpret it _. If anyone has a suggestion pleases post.
      TX

      Comment

      • Kaloyan Krumov
        New Member
        • Oct 2010
        • 16

        #4
        Done

        I have managed to do it:
        Hope this code will help someone else as i found alot of q about such thing and no answers:
        Code:
        Private Sub SCCountry_AfterUpdate()
        Dim mask As String
        
        mask = ""
        mask = DLookup("PHCODE", "Countries", "Countryid='" & Me.SCCountry & "'")
        
        SCPhone1.InputMask = "(+" & Replace(Replace(mask, "9", "\9"), "0", "\0") & ")##########"
        SCPhone2.InputMask = "(+\" & Replace(Replace(mask, "9", "\9"), "0", "\0") & "\)##########"
        SCMPhone3.InputMask = "(+\" & Replace(Replace(mask, "9", "\9"), "0", "\0") & "\)##########"
        SCFAX1.InputMask = "(+\" & Replace(Replace(mask, "9", "\9"), "0", "\0") & "\)##########"
        SCFAX2.InputMask = "(+\" & Replace(Replace(mask, "9", "\9"), "0", "\0") & "\)##########"
        SCMail.InputMask = "#############" & "@" & "#################" & "." & "###"
        
        End Sub

        Comment

        Working...