Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the Input Mask of a Field based on the content of another in Access 1

Status
Not open for further replies.

CVesta81

Technical User
May 17, 2012
23
CA
Hello,

Is it possible to change the input mask of a particular field based on the content of another? My example here is I have a field named, "zipcode" and I would like to change the input mask of that field depending if the country field reads, "USA" or "Canada". As you may or may not know, the format of the United States zipcode and the Canadian zip code are very much different. The United States zipcode is 00000-0000 and the Canadian zipcode is xxx xxx. Any thoughts on how to do this?

Thanks,
Chris
 

Did you try something like:
Code:
Select Case fldCountry.Text
  Case "USE"
    fldZip.Mask = "#####-###"
  Case "Canada"
    fldZip.Mask = "###-###"
End Select

Have fun.

---- Andy
 
I have not. Where would I place such code? Would I use this in the "On Current" part of the form?
 
OK,

So here is my code. It doesn't appear to be working. What am I doing wrong?

Code:
Private Sub Form_Current()

Me.Country.SetFocus
    
    Select Case Country.Text
        Case "USA"
            Zip.InputMask = "#####-####"
        Case "CANADA"
            Zip.InputMask = "??? ???"
    End Select
    
Me.AddressType.SetFocus
    
End Sub
 
You don't need to set the focus and should use the default/value property rather than Text. And, you need to tell us what is happening not just "doesn't appear to be working".

Code:
Private Sub Form_Current()
    Select Case Me.Country.Value
        Case "USA"
            Me.Zip.InputMask = "#####-####"
        Case "CANADA"
            Me.Zip.InputMask = "??? ???"
    End Select
End Sub

Duane
Hook'D on Access
MS Access MVP
 
I got it to work. My only question is I'm assuming this code doesn't work correctly if I have a continuous form with both Canada and USA in the form. I tried it and it seemed to switch back and forth between formats when I would click on the different records. Anyway around this? If not, I can live with these results.
 
You could, perhaps, have two Controls, both of which are Bound to the Zipcode Field in the Table.

Then, using Conditional Formatting from the Format Menu or Ribbon, use the Value of the 'country' Field to determine which one of the Controls to Enable and which one to Disable. In this way you can use a different, appropriate Input Mask for each Control.

Like Duane, I don't use Input Masks. IMHO, too much trouble for too little gain!

Linq ;0)>

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top